9

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.

Community
  • 1
  • 1
Marty Chang
  • 6,269
  • 5
  • 16
  • 25
  • I think the second commit is a merge commit. To avoid it, you have merge it manually and then push it to GitHub. GitHub does not have the feature to dismiss the merge commit. Check [here](https://stackoverflow.com/questions/16358418/how-to-avoid-merge-commit-hell-on-github-bitbucket). – xuhdev Apr 07 '16 at 22:22

1 Answers1

10

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

Xiong Chiamiov
  • 13,076
  • 9
  • 63
  • 101
  • So seems like there's now way to avoid the merge commit in GitHub... That really sucks. I generally love the GitHub pull request UI, but these merge requests are annoying and definitely confused me, because the diff shows exactly the same diff as what the squashed commit preceding it shows. – Marty Chang Apr 08 '16 at 19:22
  • 3
    Merge commits make a lot more sense when you look at [a tree view of history](http://stackoverflow.com/q/5382255/120999), which unfortunately GitHub doesn't provide. I love GitHub, but as the years go on I spend more and more time using `git` tools in the terminal instead of the "pretty" views they provide, since it inevitably ends up being more confusing when you're trying to do something beyond the slightly basic operations. – Xiong Chiamiov Apr 08 '16 at 22:03