Merge Pull Request

In this short post, we briefly list the main CLI commands for merging a pull request.

Preparation

Make sure your local committer identity is correct

git config user.name "YourName"
git config user.email "your-github-verified-email@address.ex"

Fetch upstream main branch

git fetch upstream main

Check PR Changes

Checkout PR and rebase

git fetch https://github.com/<author>/<repository>.git <branch>:pr-<pr_number>
git git switch pr-<pr_number>
git rebase upstream/main

Display stats and inspect

git log --oneline upstream/main..HEAD
git diff --stat upstream/main..HEAD

Merge to Main Branch

Update main branch

git switch main
git pull --ff-only upstream main
git push

Squash and merge PR to main branch

git merge --squash --ff-only pr-<pr_number>
git commit [--author="<author>"] # e.g., --author="Author Name <author@email.ex>"

Verify and Push

Verify before pushing

git log --oneline -n 5
git show --format=fuller --no-patch HEAD
git show --stat --summary HEAD
git push --dry-run upstream main

Push to upstream repository

git push upstream main



Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • Create GitHub Pull Request
  • Zsh and Oh-My-Zsh Installation Guide
  • Workaround: Execute Maven Project w/ Dependency on Incubated Module
  • GitHub SSH Key
  • Tensorflow Federated Tutorial