Hone

Lessons · Git · fast-forward: no merge needed

Bringing a branch in

git merge other brings other's commits onto your branch. If your branch has not moved, Git fast-forwards: the pointer moves up and no new commit is made.

Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.

What it is for

Merging is how parallel work becomes one history. Knowing when it fast-forwards and when it records a merge commit tells you what the log will look like afterwards.

How to think about it

Switch to the branch that should receive the work, then merge the other one in. Read the output: Fast-forward means nothing to reconcile; a merge commit means both sides had moved.

Worked example

git switch -c feature && echo f > f.txt && git add f.txt && git commit -q -m "Add f"
One commit on feature.
git switch main
Back on main, which has not moved.
git merge feature
Fast-forward: main's pointer moves up to feature; no new commit.
git log --oneline -1
The tip of main is feature's commit.

Your turn

Bring the finished branch onto main.

git merge 

The trap

A fast-forward leaves no record that a branch existed. Teams that want the history to show the branch merge with --no-ff.

Practise fast-forward: no merge needed on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.