Branching and Merging
Branches let you work on features, fixes, or experiments in isolation.
Creating and switching branches
bash
# Create a new branch
git branch feature/login
# Switch to it
git checkout feature/login
# Or do both at once
git checkout -b feature/loginMerging branches
When your feature is ready, merge it back into main:
bash
# Switch to main
git checkout main
# Merge the feature branch
git merge feature/loginHandling merge conflicts
When two branches change the same line, Git can't auto-merge:
code
<<<<<<< HEAD
const port = 3000;
=======
const port = 8080;
>>>>>>> feature/loginTo resolve: edit the file, choose the correct version, remove the markers, then:
bash
git add .
git commit -m "Resolve merge conflict in config"Branch strategies
Feature branches — One branch per feature (feature/auth, feature/search)
Git Flow — main, develop, feature/*, release/*, hotfix/*
Trunk-based — Short-lived branches merged quickly to main
For small teams, simple feature branches are usually enough.