What is it?
A branch is an independent line of development. Every new feature or bug fix gets its own branch — changes are isolated until merged back.
Why does it matter?
Branches are the core of professional development. Without them all developers work on the same code causing constant conflicts.
Learn Git branches — create, switch, merge, delete, and rebase.
Real-World Use Cases
- 🌿 Feature development - Create feature/user-auth branch — develop and test in isolation, merge when complete.
- 🐛 Bug fix isolation - Create fix/login-crash branch — fix, test, merge without disrupting feature work.
- 🚀 Release management - Create release/v2.0 branch for final testing while main continues receiving features.
- 👁 Code review - Push branch, open Pull Request — teammates review before code reaches main.
Create and Switch
git checkout -b feature/user-auth # create and switch
git branch # list branches
git switch main # switch back
git branch -d feature/user-auth # delete merged branch
Merge Branch
git checkout main
git merge feature/user-auth
git merge --no-ff feature/auth -m "Merge: add user auth"
git branch --merged # see merged branches
Rebase for Clean History
git checkout feature/user-auth
git rebase main # replay commits on top of main
git rebase -i HEAD~3 # interactive: squash, reword, drop
Q: What is the difference between merge and rebase?
merge creates a merge commit joining two histories. rebase moves your commits to the tip of the target — creating linear history. Use merge for shared branches (main). Use rebase for local feature branches before merging.
Comments (0)
No comments yet. Be the first!
Leave a Comment