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

Git Branch Introduction

एक branch एक wild नई ending try करने के लिए अपनी story की एक copy बनाने जैसा है। आप इसके साथ safely खेल सकते हैं जबकि original story untouched रहती है।
Syntax
bash
git branch branch_name
git switch branch_name

एक Git Branch क्या है?

एक branch development की एक independent line के लिए Git का mechanism है -- under the hood यह बस एक commit की ओर एक movable pointer है, यही वजह है कि एक बनाना instant और cheap है, आपको अपने stable code को risk किए बिना freely experiment करने देते हुए।

उदाहरण: What is a Git Branch?

bash
git branch feature-login

Branches क्यों इस्तेमाल करें?

Branches अलग-अलग काम को isolation में होने देते हैं: एक developer एक feature बनाता है, दूसरा एक bug fix करता है, और unfinished changes का कोई भी set तब तक accidentally production में running चीज़ नहीं तोड़ सकता जब तक इसे deliberately merge न किया जाए।

उदाहरण: Why Use Branches?

bash
git branch bugfix-header
git branch feature-payment

Default Branch

हर repository एक default branch से शुरू होती है -- conventionally main (या पुराना master) नाम की -- जो convention से project की current stable, deployable state represent करती है, भले ही Git इसे technically सिर्फ एक और branch मानता हो।

उदाहरण: The Default Branch

bash
git branch
# * main

Local बनाम Remote Branches

एक local branch सिर्फ आपकी अपनी machine पर exist करता है जब तक आप इसे push न करें; एक remote branch वह है जो GitHub जैसे server पर hosted है। आप remote branches fetch करते हैं यह देखने के लिए कि teammates ने क्या किया है इससे पहले कि decide करें उन changes को locally merge करना है या नहीं।

उदाहरण: Local vs Remote Branches

bash
git branch
git branch -r

Basic Branch Workflow

Everyday branch workflow है: अपने task के लिए एक branch बनाएँ, इस पर switch करें, वहाँ अपने changes commit करें, खत्म होने पर उन commits को वापस main में merge करें, फिर repository tidy रखने के लिए अब-अनावश्यक branch delete करें।

उदाहरण: Basic Branch Workflow

bash
git branch feature-x
git checkout feature-x
git commit -m "Add feature"
git checkout main
git merge feature-x
git branch -d feature-x
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. यह सोचना कि एक branch project की एक पूरी copy है, जबकि यह एक commit की ओर एक lightweight pointer है।
  2. git branch feature से एक branch बनाना और यह मान लेना कि आप अब इस पर काम कर रहे हैं, जबकि switch करने तक आप current branch पर ही रहते हैं।
  3. गलती से main में नया काम commit करना क्योंकि current branch पहले check नहीं किया गया था।

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.