Git without fear · Chapter 15 of 28
Merging
By the end of this chapter you can bring a finished branch into main, and tell a fast-forward from a merge commit before Git makes one. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Branches
- 3 tasks
- Git
- In the all labs plan
The first 2 chapters of Git without fear are free. This one comes with the all labs plan.
Why you need this
Two branches are done and approved. fix-typo is yours: the new menu said "Masla chai" and nobody noticed except Meera's mother. loyalty-card is Anjali's, started this afternoon, before Ravi added the opening hours to main. Kabir wants both on main, the typo fix as a plain step forward with no extra commit, and he wants you to know which merge made a commit.
So far you can make branches and switch between them, but nothing comes back to main. Copying the files over by hand loses the commits, who made them and why. Bunty's view is "merging is merging, no?", and last week he merged in the wrong order and left main with a merge commit nobody needed.
What you build: 3 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
Merge fix-typo into main as a fast-forward
Merge fix-typo into main first, so main just moves forward to it.
1. Run git log --oneline --graph --all to see both branches.
2. Make sure you are on main.
3. Merge fix-typo into main with git merge. Do this before you merge loyalty-card.
4. Git prints Fast-forward. It makes no merge commit.
To pass: main has "Fix the masala chai typo" on its own line, with no merge commit for it, and menu.txt on main says Masala chai 40. Merge fix-typo before loyalty-card, and do not use --no-ff. If Git made a merge commit, run lab reset and merge again in this order.
- Task 2
Merge loyalty-card into main with a merge commit
Now merge loyalty-card into main. This time Git makes a merge commit.
1. Stay on main.
2. Merge loyalty-card into main.
3. Git opens the editor with the message Merge branch 'loyalty-card'. Keep it, save and close the editor. Or add --no-edit to skip the editor.
4. Run git log --oneline --graph. You see the two lines join.
To pass: main has a merge commit that joins in loyalty-card's last commit, "Explain how to stamp the card". Make the merge while you are on main. Do not change the loyalty-card branch. main has loyalty.txt and still has hours.txt.
- Task 3 · interview question
Interview: what is a fast-forward?
Interview question: what is a fast-forward merge?
1. Think about your first merge. Did Git make a new commit? What moved?
2. Write one line in your own words.
3. Save it in answer.txt, in the chapter folder. echo with > writes text into a file.
To pass: answer.txt says that the branch just moves forward, or that Git makes no new commit.
What you will learn
- git merge: brings another branch's commits into the branch you are on.
- A fast-forward: when main has nothing new, Git just moves main's label.
- A merge commit: when both sides have moved on, a new commit with two parents joins them.
- Why the order matters: one merge can turn the next fast-forward into a merge commit.
More in Branches
Build "Merging" yourself
Your first week on Tapri’s team, and every Git situation it throws at you. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Git without fear are free. This one comes with the all labs plan.