AI Hints
Home›Git & GitHub Tutorial›Merging Pull Requests
Git & GitHub · Lesson 72 of 144

Merging a Pull Request

Three ways to merge.

⏱ 2 min read▶ Video at 1:18:40🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

When a pull request is approved, someone clicks the green merge button. But that button has three options. Each one shapes your history differently.

Merging a Pull Request
From the video: Merging a Pull Request
  • Approved? Click merge
  • The button has three options
  • Each shapes history differently

The three merge options

Create a merge commit keeps every commit from the branch, and adds a merge commit, just like git merge. Squash and merge combines all the branch's commits into one single commit on main. Rebase and merge replays each commit on top of main, with no merge commit. Your team usually picks one, and sticks with it.

OptionWhat lands on mainHistory
Create a merge commitall commits + a mergeexact, with branches
Squash and mergeone combined commitshort and tidy
Rebase and mergeall commits, replayedstraight line

Squash, on your computer

You can see squashing on your own computer too. Git merge, dash dash squash, stages all the branch's changes, without committing. Then one commit holds the whole feature. The log shows one clean commit, instead of two.

git
git switch main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
git merge --squash add-blog
Updating f63a17a..a05e8bd
Fast-forward
Squash commit -- not updating HEAD
 blog.html  | 1 +
 index.html | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 blog.html
git commit -m "Add blog (#1)"
[main e82ebe0] Add blog (#1)
 2 files changed, 2 insertions(+)
 create mode 100644 blog.html
git log --oneline -n 2
e82ebe0 (HEAD -> main) Add blog (#1)
f63a17a (origin/main) Link to about page

Summary

Merge commit keeps everything, squash makes one commit, rebase makes a straight line. Next, tidying up after a merge.

Key takeaways
  • Merge commit
  • Squash and merge
  • Rebase and merge
Next up: After the Merge — tidying up