I have a longer version of this answer in Merge pull request in git causes the upstream branch to go ahead of origin but here is the shorthand equivalent. All assume you're on the base branch to begin with, i.e., git checkout branch
. The message below is Merge pull request #number from repository
and the hash
is automatically computed from the pull request.
Create a merge commit
git merge --no-ff -m message hash
Squash and merge
git merge --no-commit --squash hash && git commit -m message
Rebase and merge
git rebase --force-rebase hash
(Note that the rebase-and-merge won't function if merge conflicts occur. It's not clear to me whether the GitHub system checks for this with --merge
or without it, or some other way entirely. The pull request has already checked for merge conflicts with a git merge
with or without --squash
; refs/pull/head/number
always exists, but refs/pull/merge/number
only exists if there are no such conflicts, I think. They—GitHub—also keep track of whether the "base branch" used to create the pull request was/is up to date, but it's not quite clear precisely how they do that.)