← Back to Git Course | Chapter 2: Basic Commands | Lesson 1 of 18

Git init Command

git init एक ordinary folder के अंदर एक बिल्कुल नई notebook रखने और कहने जैसा है 'यहाँ सब कुछ track करना शुरू करो'। Folder एक ऐसी जगह बन जाता है जहाँ Git आपके काम को देखता है।
Syntax
bash
git init [directory_name]
git init -b branch_name

git init क्या है?

git init वह single command है जो किसी भी ordinary folder को एक active Git repository में बदल देता है -- यह object database, refs, और configuration रखने वाली hidden .git directory बनाता है जो Git को changes track करना शुरू करने के लिए चाहिए।

उदाहरण: What is git init?

bash
git init

एक Empty Repository Initialize करना

आप एक बिल्कुल नई directory बनाने और इसे एक step में एक repository की तरह initialize करने के लिए git init <folder-name> भी चला सकते हैं, जो scratch से एक project शुरू करते समय एक मौजूदा folder convert करने के बजाय handy है।

उदाहरण: Initializing an Empty Repository

bash
git init my-new-project

Custom Default Branch

नई repositories को एक starting branch name चाहिए, और modern Git आपको git init -b main (या init.defaultBranch के through एक global default set करके) से explicitly इसे चुनने देता है बजाय installed default जो भी हो उसे accept करने के।

उदाहरण: Custom Default Branch

bash
git init -b main

एक Repository को दोबारा Initialize करना

पहले से एक repository वाले folder के अंदर दोबारा git init चलाना पूरी तरह safe है -- Git आपकी मौजूदा commits या files को नहीं छूएगा, यह सिर्फ किसी भी missing configuration files को दोबारा बनाता है, जो कभी-कभी एक corrupted setup repair करने के लिए उपयोगी है।

उदाहरण: Re-initializing a Repository

bash
git init

एक Bare Repository Initialize करना

एक bare repository, git init --bare से बनाई गई, में checked-out files की कोई working directory बिल्कुल नहीं होती -- यह सिर्फ raw tracking data रखती है, जो exactly वह है जो आप एक server पर चाहते हैं जो पूरी तरह एक central hub की तरह act करे जिसे दूसरे push और pull करें।

उदाहरण: Initializing a Bare Repository

bash
git init --bare
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. पहले से एक Git repository वाले folder के अंदर, या एक parent folder में git init चलाना, ताकि project structure गलत तरीके से track हो।
  2. यह उम्मीद करना कि git init पहली commit या files बनाएगा, जबकि यह सिर्फ empty .git folder बनाता है।
  3. यह surprise होना कि पुराने setups पर branch का नाम master है, जबकि आप git init -b main से नाम चुन सकते हैं।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.