How to do a fast-forward merge on GitHub?

It's possible to do a fast-forward merge via the command line and then push it to Github. The Github pull request CLI instructions do explicitly say to use git merge --no-ff, but it also appears to work with a fast-forward, which preserves the git commit hash and closes the open pull request:

$ git checkout master
$ git merge your-branch # the branch which has an open pull request
$ git push

At this point, Github will automatically detect that the branch was merged and the pull request will be closed. If you have the "pull request" page open in your web browser you will see it asynchronously change the state to: "X merged commit into master", "Pull request successfully merged and closed".


Looks like GitHub does not support this – and this is a TERRIBLE affair. You basically CANNOT run an atomic, linear commit strategy (the best there is) using the GitHub UI.

Note that Bitbucket DOES support this, and has much more fine-grained options for setting up the PR landing/integration strategy. Namely the 'Rebase, fast-forward' option which does a --ff-only update of the target/mainline branch. It also has a 'Rebase, merge' option which lets you run a rebase on target (so that your commits are linear) but integrates using a merge commit (if you want to track that the commits are all part of one logical unit/PR).

Both of these options seem superior to GitHub's limited options of either using non-linear merge commits (GitHub's 'Merge pull request' option) or linear rebase ('Rebase and merge' option), which does achieve linearity but creates duplicate commits on the source branch, thus always requiring manual Hard Resets locally if you want to keep things clean and in sync.

So... time to switch your repo provider it seems!


An alternative could be to setup a Fast Forward PR GitHub Action:

Merge pull request using fast forward only, if possible, moving base branch (target branch) to head branch (source branch). Comment success or failure messages on the pull request issue. The goal is to keep branches equal at the end of the merge.


Based on GitHub's documentation and my own testing, it is not possible to do a fast-forward with the same commit hash.

The rebase and merge behavior on GitHub deviates slightly from git rebase. Rebase and merge on GitHub will always update the committer information and create new commit SHAs, whereas git rebase outside of GitHub does not change the committer information when the rebase happens on top of an ancestor commit. For more information about git rebase, see the "Git rebase" chapter from the Pro Git book.

https://docs.github.com/en/github/administering-a-repository/about-merge-methods-on-github