Git Branching & Team Collaboration — Work Like a Real DevOps Engineer
🚀 Git Branching & Team Collaboration — Work Like a Real DevOps Engineer
📌 Introduction
Real world me koi bhi project ek banda nahi banata. Team hoti hai. Aur har developer apna kaam independently karta hai.
Problem tab aati hai jab sab ek hi code ko modify karte hain.
👉 Solution = Git Branching
🌿 What is Branch?
ELI5: Branch matlab ek copy jahan tum apna kaam karte ho bina main code ko disturb kiye.
DevOps: Independent development line for features, bug fixes, releases.
🎯 Why Branching?
- Main code safe rehta hai
- Team parallel kaam karti hai
- Bug fix isolated hota hai
- Testing easy hoti hai
💻 Important Commands
git branch
👉 All branches show karta hai
git checkout -b feature-login
👉 New branch + switch
git switch main
👉 Branch switch
git merge feature-login
👉 Merge branch
🚀 PROJECT 1: Feature Development Workflow (Step-by-Step)
Scenario: Tum login feature bana rahe ho
Step 1: Ensure latest code
git pull origin main
👉 Why: Tum outdated code pe kaam na karo
Step 2: Create feature branch
git checkout -b feature-login
👉 Safe environment create ho gaya
Step 3: Code changes
Login page + API likho
Step 4: Save changes
git add . git commit -m "Login feature completed"
👉 Code Git me save ho gaya
Step 5: Switch to main
git switch main
Step 6: Merge feature
git merge feature-login
👉 Feature ab main code me aa gaya
Final Result: Feature successfully integrated
🚀 PROJECT 2: Team Collaboration (Real Company Scenario)
Scenario: 3 developers same project pe kaam kar rahe hain
Step 1: Sab latest code pull karte hain
git pull origin main
Step 2: Har developer apni branch banata hai
git checkout -b feature-ui
git checkout -b feature-api
git checkout -b feature-db
Step 3: Sab apna kaam karte hain
Step 4: Commit changes
git add . git commit -m "Work done"
Step 5: Merge ek ek karke
git switch main git merge feature-ui git merge feature-api git merge feature-db
⚠ Possible Issue: Merge conflict
👉 Fix: File open karo → conflict resolve → commit
Final Result: Team ka code safely integrate ho gaya
🚀 PROJECT 3: Bug Fix Workflow
Scenario: Production me login error aa gaya
Step 1: Bugfix branch create
git checkout -b bugfix-login
Step 2: Bug fix karo
Step 3: Commit fix
git commit -m "Login bug fixed"
Step 4: Merge to main
git switch main git merge bugfix-login
Result: Production issue solved
🚀 PROJECT 4: Release Workflow
Scenario: New version release karna hai
Step 1: Release branch
git checkout -b release-v1
Step 2: Testing + bug fixes
Step 3: Final commit
git commit -m "Release ready"
Step 4: Merge to main
git switch main git merge release-v1
Result: Stable version deployed
🚀 PROJECT 5: Wrong Branch Mistake & Fix
Scenario: Tumne galti se main branch me commit kar diya
Step 1: Check commit
git log --oneline
Step 2: Create correct branch
git checkout -b feature-login
Step 3: Move commit
git cherry-pick COMMIT_ID
Step 4: Reset main
git switch main git reset --hard HEAD~1
Result: Commit correct branch me move ho gaya
⚠️ Common Mistakes & Fix
- Wrong branch commit → cherry-pick
- Merge conflict → manual resolve
- Lost code → git reflog
- Wrong merge → git reset
🎯 Final Words
Next, we’ll go deeper into Git and understand one of the most important and confusing parts — Merge Conflicts and how to resolve them in real projects.