Branches let you experiment without breaking main. Feature branches are the default collaboration model.
Commands
git branch feature/login
git switch feature/login # or: git checkout feature/login
# ... work, commit ...
git switch main
git merge feature/login
Merge conflicts
When two branches edit the same lines, Git marks conflicts in files. You edit to the correct result, git add, then complete the merge.
Self-check
- What is a branch pointer conceptually?
- When might you prefer rebase over merge? (high level)
Interview prep
- What is a branch in Git?
A movable pointer to a commit. New commits advance the current branch; other branches can advance independently until you merge or rebase.
- What happens in a merge conflict?
Two branches changed the same region of a file; Git inserts conflict markers. You edit to the correct combined content, then
git addand complete the merge or rebase.