Git Branches
What is a Branch?
- Allows to keep track of different changes separately.
- Used to develop features, fixes, or experiments safely without affecting main code.

HEAD and Branch
-
HEADpoints to the current branch -
Switching branches moves
HEAD - Check active branch:
cat .git/HEADorgit branch


Branch Commands
List branches
git branch→ local branchesgit branch -a→ all branches (local + remote)
Create a branch
git branch bug-fix
Switch branch
git checkout bug-fixgit switch bug-fix
Create & switch
git checkout -c bug-fixgit switch -c bug-fix
Rename branch
git branch -m old-name new-namegit branch -M main
Delete branch
git branch -d bug-fixgit branch -D bug-fix(force)

Remote Branches
git branch -r→View remote branchesgit push origin bug-fix→Push a branchgit push origin --delete bug-fix→Delete remote branch
Best Practices
- Commit before switching branches
- One feature or fix per branch
- Delete branches after merge