← Back to Git Course | Chapter 3: Branching | Lesson 2 of 9

Git branch Command

git branch आपके बनाए सभी अलग-अलग story copies की list देखने जैसा है, जिस पर आप इस समय काम कर रहे हैं उसके बगल में एक star के साथ।
Syntax
bash
git branch
git branch branch_name
git branch -d branch_name
git branch -r

Branches List करना

अकेला git branch आपकी repository की हर local branch list करता है, आपकी current को एक asterisk से mark करते हुए; इसके बजाय remote-tracking branches देखने के लिए -r add करें, या दोनों local और remote साथ देखने के लिए -a।

उदाहरण: Listing Branches

bash
git branch
git branch -r
git branch -a

एक नई Branch बनाना

git branch <name> आपकी current commit की ओर point करने वाली एक नई branch बनाता है बिना इस पर switch किए; इसके बजाय एक starting commit hash add करना आपको history में किसी भी specific point से branch off करने देता है, सिर्फ जहाँ आप इस समय हैं वहाँ से नहीं।

उदाहरण: Creating a New Branch

bash
git branch feature-cart

एक Branch Delete करना

git branch -d <name> एक branch delete करता है, लेकिन सिर्फ तभी अगर इसकी commits पहले से कहीं और merge हो चुकी हों -- Git अन्यथा unmerged काम को protect करने के लिए deletion block कर देता है, और उस safeguard को override करने के लिए आपको ज़्यादा forceful -D चाहिए होगा।

उदाहरण: Deleting a Branch

bash
git branch -d feature-cart
git branch -D feature-cart

एक Branch Rename करना

git branch -m <old> <new> एक branch rename करता है -- new name के अलावा बिना arguments के चलाकर आप इस समय checked out किसी भी branch को rename कर सकते हैं, या ऐसी branch rename करने के लिए दोनों names specify करें जिस पर आप इस समय नहीं हैं।

उदाहरण: Renaming a Branch

bash
git branch -m old-name new-name

Upstream Branches Inspect करना

git branch -vv हर local branch को उसके remote-tracking counterpart के साथ और यह दिखाता है कि यह कितनी commits आगे या पीछे है, जो उन branches ढूँढने का सबसे तेज़ तरीका है जिन्हें काम जारी रखने से पहले एक push या pull चाहिए।

उदाहरण: Inspecting Upstream Branches

bash
git branch -vv
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 branch feature चलाना और edit करना शुरू करना, original branch पर रहते हुए क्योंकि git branch switch नहीं करता।
  2. एक unmerged branch पर git branch -d feature इस्तेमाल करना और एक error पाना, फिर -D इस्तेमाल करना और इसकी commits खो देना।
  3. जिस branch पर आप इस समय हैं उसे delete करने की कोशिश करना, जो तब तक fail होता है जब तक आप किसी दूसरी पर switch न करें।

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.