Once work on a branch is ready, merging brings its changes into another branch — usually back into main.
git switch main
git merge feature-login
# Updating a1b2c3d..e5f6g7h
# Fast-forward
# login.php | 20 ++++++++++++++++++
# 1 file changed, 20 insertions(+)The merge command runs on the branch receiving the changes (main, here), pulling in the named branch (feature-login).
| Fast-forward merge | A real merge commit |
|---|---|
| main hasn't changed since the branch split off | Both main and the branch have new commits since they split |
| Git simply moves main's pointer forward — no new commit created | Git creates a new commit specifically joining the two histories |
| A clean, linear history | A history showing exactly where branches diverged and rejoined |
# Force a real merge commit even when a fast-forward is possible —
# some teams prefer this for a clearer history of feature branches
git merge --no-ff feature-loginOnce merged, a feature branch has usually done its job — deleting it keeps the branch list from growing indefinitely.
git branch -d feature-logingit log --oneline --graph --all
# * f7g8h9i Merge branch 'feature-login'
# |\
# | * e5f6g7h Add login validation
# | * d4e5f6g Add login form
# |/
# * a1b2c3d Initial commitWhat happens next if this doesn't go cleanly
A merge that touches the same lines a branch and main both changed can't be resolved automatically — that's a merge conflict, covered in the next lesson, and it's a completely normal part of working with branches, not a sign something went wrong.