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

Git Branch Strategies

एक branching strategy एक बड़ी kitchen के लिए rules के एक set जैसी है कि कौन कहाँ cook करता है और dishes table पर कब जाती हैं। यह teams को एक-दूसरे से टकराने से बचाती है।

Git Flow Strategy

Git Flow parallel develop और main branches, plus dedicated feature/, release/, और hotfix/ branches के आसपास बना एक heavyweight, structured branching model है -- scheduled releases वाले projects के लिए well-suited, लेकिन अक्सर छोटी, fast-moving teams के लिए overkill।

उदाहरण: Git Flow Strategy

bash
git checkout develop
git checkout -b feature/login
git checkout -b release/1.0 develop
git checkout -b hotfix/critical-bug main

GitHub Flow

GitHub Flow इसे एक rule तक strip कर देता है: जो भी आप काम कर रहे हैं उसके लिए main से branch करें, ready होने पर एक pull request खोलें, और review होते ही वापस main में merge करें -- उन teams के लिए काफी simple जो fixed schedule के बजाय continuously deploy करती हैं।

उदाहरण: GitHub Flow

bash
git checkout main
git checkout -b add-search-bar
# open a pull request, review, then merge into main

GitLab Flow

GitLab Flow feature branches के साथ environment branches (जैसे staging और production) add करता है, ताकि code visibly हर environment से गुज़रे जैसे यह promote होता है -- आपको एक audit trail देते हुए कि exactly क्या कहाँ deployed है।

उदाहरण: GitLab Flow

bash
git checkout -b staging main
git checkout -b production staging

Trunk-Based Development

Trunk-Based Development simplicity को और भी आगे push करता है: हर कोई एक shared trunk में frequently commit करता है, अक्सर एक दिन में कई बार, बहुत short-lived branches (या बिल्कुल भी नहीं) इस्तेमाल करते हुए specifically बड़े merge conflicts का दर्द कम करने के लिए।

उदाहरण: Trunk-Based Development

bash
git checkout main
git checkout -b quick-fix
git commit -m "Small change"
git checkout main
git merge quick-fix

Stale Branches साफ करना

आप जो भी strategy follow करें, git branch --merged main को git branch -d के साथ combine करना उन feature branches साफ कर देता है जिनका काम पहले से main पर पहुँच चुका है, project बढ़ने के साथ branch list को clutter जमा होने से बचाते हुए।

उदाहरण: Cleaning Stale Branches

bash
git branch --merged main
git branch -d old-feature
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. अक्सर deploy होने वाले एक छोटे project के लिए Git Flow इस्तेमाल करना, develop और release branches add करते हुए जो सिर्फ team को धीमा करती हैं।
  2. long-lived feature branches को main से दूर drift होने देना, बड़े painful merges का कारण बनते हुए।
  3. एक team के अंदर strategies mix करना, जैसे दूसरे feature branches इस्तेमाल करते हुए directly main में commit करना।

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.