Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why merged pull request in GitHub creates duplicate commit?

At my company we ask developers to squash commits on feature branches before merging into develop. Once squashed, the developer pushes to GitHub and logs into GitHub to create a pull request.

When the pull request is merged, we end up seeing two commits in the history of the develop branch:

  1. A commit saying "merged pull request"
  2. The single, squashed commit from the feature branch

Why does this happen? And how can we avoid it? I've read a similar Q&A about avoiding "merge commit hell" but my goal is to use the GitHub UI to create, track, and discuss pull requests.

like image 723
Marty Chang Avatar asked Apr 07 '16 21:04

Marty Chang


1 Answers

The commit you're seeing is a merge commit; generally these are auto-created by git any time you do a non-fast-forward merge, but you can also force one to always be created. And that is what GitHub does when you use the merge button.

If you don't want merge commits, then you need to cherry-pick commits onto master instead of using the merge button. There is no way to do this within the GitHub web UI.

Edit: GitHub has now added squash and merge and rebase and merge capabilities within their web UI:

enter image description here

like image 86
Xiong Chiamiov Avatar answered Sep 17 '22 18:09

Xiong Chiamiov