Merging: merge commit, squash and rebase on GitHub
What merging does, the three options behind GitHub's merge button and what each leaves in the history, fast-forward in plain words, and how to check whether a change is really in main.
Lesson 5 of 15~31 min of learningIncludes ~16 min for questions and tasks
Contents1 of 63 steps
Alex Tutor
Daniel
You
Alex Tutor
feature/free-delivery-1000 into main. Until that happens, the site keeps saying 800.Alex Tutor
8be2f70Add cat treats bundlemain5c1d7e2Set freeDeliveryFrom to 1000a8f40b9Update delivery page textd36b9c5Update cart hint textfeature/free-delivery-1000
Commit graph, oldest first: Pull request #133 before the merge 1. commit 8be2f70 on main "Add cat treats bundle" 2. branch feature/free-delivery-1000 starts from commit 8be2f70 3. commit 5c1d7e2 on feature/free-delivery-1000 "Set freeDeliveryFrom to 1000" 4. commit a8f40b9 on feature/free-delivery-1000 "Update delivery page text" 5. commit d36b9c5 on feature/free-delivery-1000 "Update cart hint text"
You
main. Three ahead, zero behind: main hasn't moved since Daniel started.Alex Tutor
main will contain all three changes: the new number in the config, the delivery page text and the hint in the cart. The branch itself stays as it was.Alex Tutor
Question 1
Daniel merges feature/free-delivery-1000 into main. What changes?
Alex Tutor
Merge pull request, with a small arrow next to it. The arrow opens three options.You
Create a merge commit, Squash and merge, Rebase and merge. Which one gives the right result?Alex Tutor
main are identical: the threshold is 1000 either way. What differs is the history you'll read afterwards.You
Daniel
Alex Tutor
main looks like afterwards.Alex Tutor
Question 2
The three options in GitHub's merge button leave different text in the files of main.
Alex Tutor
Create a merge commit. GitHub adds the branch's commits to main as they are and ties the two lines together with one extra commit, a merge commit.Alex Tutor
8be2f70Add cat treats bundle5c1d7e2Set freeDeliveryFrom to 1000a8f40b9Update delivery page textd36b9c5Update cart hint textfeature/free-delivery-1000e4b7a90Merge pull request #133main
Commit graph, oldest first: Option 1: a merge commit 1. commit 8be2f70 on main "Add cat treats bundle" 2. branch feature/free-delivery-1000 starts from commit 8be2f70 3. commit 5c1d7e2 on feature/free-delivery-1000 "Set freeDeliveryFrom to 1000" 4. commit a8f40b9 on feature/free-delivery-1000 "Update delivery page text" 5. commit d36b9c5 on feature/free-delivery-1000 "Update cart hint text" 6. merge commit e4b7a90: feature/free-delivery-1000 merged into main "Merge pull request #133" (highlighted)
You
e4b7a90. So that commit has two parents: the previous commit on main and the last one on the branch.Alex Tutor
main grows by four entries: Daniel's three commits and the merge commit.Daniel
git merge. Nothing is rewritten: my commits keep their hashes, and you can always see where a branch started and where it came back.You
main.Alex Tutor
Question 3
Pull request #140 was merged with Create a merge commit. Which statements are true? Select all that apply.
r1Add returns paget1Add returns formt2Validate order numberfeature/returns-formr2Fix typo on returns pager3Merge pull request #140main
Commit graph, oldest first: Pull request #140 merged with a merge commit 1. commit r1 on main "Add returns page" 2. branch feature/returns-form starts from commit r1 3. commit t1 on feature/returns-form "Add returns form" 4. commit t2 on feature/returns-form "Validate order number" 5. commit r2 on main "Fix typo on returns page" 6. merge commit r3: feature/returns-form merged into main "Merge pull request #140"
Alex Tutor
Squash and merge. GitHub takes all the changes from the branch and puts them into main as one new commit.Alex Tutor
8be2f70Add cat treats bundle5c1d7e2Set freeDeliveryFrom to 1000a8f40b9Update delivery page textd36b9c5Update cart hint textfeature/free-delivery-10006f2c8a1Raise free-delivery threshold to 1000 UAH (#133)main
Commit graph, oldest first: Option 2: squash and merge 1. commit 8be2f70 on main "Add cat treats bundle" 2. branch feature/free-delivery-1000 starts from commit 8be2f70 3. commit 5c1d7e2 on feature/free-delivery-1000 "Set freeDeliveryFrom to 1000" 4. commit a8f40b9 on feature/free-delivery-1000 "Update delivery page text" 5. commit d36b9c5 on feature/free-delivery-1000 "Update cart hint text" 6. commit 6f2c8a1: feature/free-delivery-1000 squash-merged into main "Raise free-delivery threshold to 1000 UAH (#133)" (highlighted)
You
6f2c8a1, and a dashed line instead of a solid one. And its title ends with (#133).Alex Tutor
main's history. Their changes did, packed into one commit. GitHub adds the pull request number to its title by itself.Daniel
main in module 1 looked like a straight line: one pull request, one commit. My "oops, typo" commits never get there.You
Alex Tutor
Commits tab keeps them, even after the branch has been deleted.Alex Tutor
Question 4
Pull request #140 was merged with Squash and merge. How many new commits did main get, and where can t1 and t2 still be seen?
r1Add returns paget1Add returns formt2Validate order numberfeature/returns-formr2Fix typo on returns pager3Add returns form (#140)main
Commit graph, oldest first: Pull request #140 merged with squash 1. commit r1 on main "Add returns page" 2. branch feature/returns-form starts from commit r1 3. commit t1 on feature/returns-form "Add returns form" 4. commit t2 on feature/returns-form "Validate order number" 5. commit r2 on main "Fix typo on returns page" 6. commit r3: feature/returns-form squash-merged into main "Add returns form (#140)"
Alex Tutor
Rebase and merge. GitHub replays the branch's commits on top of main, one by one. No merge commit and no squashing.Alex Tutor
8be2f70Add cat treats bundle5c1d7e2Set freeDeliveryFrom to 1000a8f40b9Update delivery page textd36b9c5Update cart hint textfeature/free-delivery-10001f6a3d8Set freeDeliveryFrom to 10002b9e5c4Update delivery page text7d0c8f1Update cart hint textmain
Commit graph, oldest first: Option 3: rebase and merge 1. commit 8be2f70 on main "Add cat treats bundle" 2. branch feature/free-delivery-1000 starts from commit 8be2f70 3. commit 5c1d7e2 on feature/free-delivery-1000 "Set freeDeliveryFrom to 1000" 4. commit a8f40b9 on feature/free-delivery-1000 "Update delivery page text" 5. commit d36b9c5 on feature/free-delivery-1000 "Update cart hint text" 6. commit 1f6a3d8 on main "Set freeDeliveryFrom to 1000" 7. commit 2b9e5c4 on main "Update delivery page text" 8. commit 7d0c8f1 on main "Update cart hint text" (highlighted)
You
main with the same messages as on the branch, but different hashes.Alex Tutor
Daniel
main hasn't changed since the branch started, there is nothing to combine. Git can simply move the name main forward to the last commit of the branch.You
main stood still while you worked. No new commit at all, just the name catching up.Daniel
Alex Tutor
Question 5
Match each way of merging with what the graph looks like afterwards.
Tap an answer, then tap the row it belongs to. You can also drag.
Create a merge commitSquash and mergeRebase and merge- Fast-forward in the terminal
Answers left to place
You
Daniel
main is one finished piece of work with a link to its pull request. Reverting it is one click.Alex Tutor
You
Alex Tutor
Question 6
Which merge option produced this history of main?
r1Add returns paget1Add returns formt2Validate order numberfeature/returns-formr2Fix typo on returns pager3Add returns formr4Validate order numbermain
Commit graph, oldest first: Pull request #140 after the merge 1. commit r1 on main "Add returns page" 2. branch feature/returns-form starts from commit r1 3. commit t1 on feature/returns-form "Add returns form" 4. commit t2 on feature/returns-form "Validate order number" 5. commit r2 on main "Fix typo on returns page" 6. commit r3 on main "Add returns form" 7. commit r4 on main "Validate order number"
Alex Tutor
Squash and merge, then Confirm squash and merge. Now the question you'll hear most often as a PM: is the change in?Open has turned into purple Merged, and the line next to it says the commit went into main.Alex Tutor
Raise free-delivery threshold to 1000 UAH#133
Merged into main today: the changes are in main
Rewrite delivery page copy#132
Open: Emma's changes are still on her branch
Fix checkout button after cart edits#134
Draft: Daniel is still working on it
You
main. Emma's #132 is still open, and the checkout fix, #134, is only a draft. Neither of those has reached main.Alex Tutor
main. Second, merged doesn't mean released.Daniel
main is deployed automatically within minutes. Other teams collect merges and ship them as a release. We'll get there in module 4.Merged, although #98 reverted it ten minutes later. Merged is a fact about the past. When in doubt, open the file in main.You
Alex Tutor
Question 7
Which of these pull requests have their changes in main right now? Select all that apply.
Add summer promo banner#129
Rewrite delivery page copy#132
Raise free-delivery threshold to 1000 UAH#133
Fix checkout button after cart edits#134
Try animated delivery badge#127
Alex Tutor
main shows only one.You
Alex Tutor
Daniel
Alex Tutor
Question 8Short answer · AI-checked task
A colleague opened pull request #133 and sees three commits in its Commits tab, but the history of main shows only one: "Raise free-delivery threshold to 1000 UAH (#133)". They think two commits were lost. Explain in 2–3 sentences what happened and where the three commits can still be found.
Write your answer and get a score with feedback from our AI reviewer.
Log in to get AI feedbackYou
Alex Tutor
That’s the lesson. You answered every task — nicely done.