World map

 

BM: Baca dalam Bahasa Melayu

World 3: Parallel Universes

Fast-forward merge

You will learn: how a finished branch joins main when main has nothing new.

The problem

The log: about has two new commits, Add about page and Say what I like. main sits two commits behind, on Add style. Terminal output: $ git log --oneline --graph --all * 203a91f (about) Say what I like * a20da6c Add about page * 270a76e (HEAD -> main) Add style * a8feb63 Add day 1 page * 6d3a9b1 Add README

Your about page is finished on its branch. But main doesn’t have it yet. How do they join?

Watch

The main label slides forward two commits and lands on Say what I like, next to about. No new commit appears.
6d3a9b1a8feb63270a76ea20da6c203a91f

On main, git merge about brings the about work in. main has nothing new, so Git just slides the note forward. That’s a fast-forward: A merge where Git just slides your branch forward. No new commit..

Watch

git merge about prints Updating, then Fast-forward, then about.html with 2 new lines. Terminal output: $ git merge about Updating 270a76e..203a91f Fast-forward about.html | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 about.html

Look for the word Fast-forward. Git made no new commit. One note just moved.

Try it

You are on main. merge: Join two storylines into one. about into it.

6d3a9b1a8feb63270a76ea20da6c203a91f

Predict

After a fast-forward, how many new commits did Git make?

Pick one answer.

Check

Where is main now?

Tap the commit main points at now.

6d3a9b1a8feb63270a76ea20da6c203a91f

You did it!

You can now merge with a fast-forward.

Go deeper (optional)

git merge --ff-only about merges only if it can fast-forward. If not, it stops safely. git merge --no-ff about always makes a merge commit. Some teams like that, so the branch shows up in history.

With --no-ff, Git makes a merge commit, Merge branch 'about', even though it could fast-forward. Terminal output: $ git merge --no-ff about Merge made by the 'ort' strategy. about.html | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 about.html $ git log --oneline --graph * e8fa618 (HEAD -> main) Merge branch 'about' |\ | * 203a91f (about) Say what I like | * a20da6c Add about page |/ * 270a76e Add style * a8feb63 Add day 1 page * 6d3a9b1 Add README