Why is branching important?
Branching allows developers to work on new features, bug fixes, or experiments without affecting the main project. It promotes collaboration, parallel development, and safer code integration.
- Keeps the main branch (often called
main
ormaster
) clean and stable. - Reduces conflicts when multiple developers are working simultaneously.
- Makes collaboration easier by isolating untested or experimental code.
- Developers can merge their work back into the main branch only after review and testing.
Git Commands for Branching
Git Commands for Branching
Create a new branch:
git checkout -b branch-name
Switch to an existing branch:
git checkout branch-name
Merge your branch into main:
git checkout main
git pull
git merge your-branch
git push
Close (delete) a branch locally:
git branch -d branch-name
Delete a branch from the remote (e.g., GitHub):
git push origin --delete branch-name