Git Branch Introduction
In this page:
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?
git branch feature-login
Branches क्यों इस्तेमाल करें?
Branches अलग-अलग काम को isolation में होने देते हैं: एक developer एक feature बनाता है, दूसरा एक bug fix करता है, और unfinished changes का कोई भी set तब तक accidentally production में running चीज़ नहीं तोड़ सकता जब तक इसे deliberately merge न किया जाए।
उदाहरण: Why Use Branches?
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
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
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
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
- यह सोचना कि एक branch project की एक पूरी copy है, जबकि यह एक commit की ओर एक lightweight pointer है।
git branch featureसे एक branch बनाना और यह मान लेना कि आप अब इस पर काम कर रहे हैं, जबकि switch करने तक आप current branch पर ही रहते हैं।- गलती से
mainमें नया काम commit करना क्योंकि current branch पहले check नहीं किया गया था।
Chapter Quiz — Complete all 9 topics to unlock
0/9 topics done
Complete these topics first: