26

I'm working on a project where "squash and merge" is the preferred approach for merging pull requests. Is there a way to make this the default option in GitHub, either for my own user, or for the project?

As it stands, it's entirely too easy to select the default option (Create a merge commit). This is made especially problematic by the fact that it is not easily undo-able, given that you generally should not be modifying repository history.

Note that this is different than How to make --squash default on a merge?, as that one refers to the command line usage of Git, whereas my question concerns functionality within the GitHub user interface.

M. Justin
  • 14,487
  • 7
  • 91
  • 130
  • 2
    I'm no GitHub expert, but it seems to me impossible: the actual default is whatever the individual user did last time. Each user thus has a different default. There's nothing in the `git push` protocol to set a default and there's no obvious knob or button on the "make pull request" section either. However, "do what I did last time" (stored in a cookie, probably) would be easy to implement and seems to be what they do. – torek Mar 09 '18 at 22:23
  • 2
    @Ray — Not a duplicate, since this is specifically referring to the functionality within the GitHub user interface for pull requests, not command line usage of Git. – M. Justin Mar 09 '18 at 22:27
  • Fair enough, retracting vote – Ray Mar 09 '18 at 22:29
  • @torek — I didn't realize it defaulted to the last option selected by the user. That actually solves my underlying issue (how not to mess up and use the wrong merge option), since all my merges will be using that option. I'm not currently in a good position to verify this, but when I do I'll accept it as an answer. – M. Justin Mar 09 '18 at 22:31
  • https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/configuring-commit-squashing-for-pull-requests – smaug Dec 22 '20 at 16:31

3 Answers3

30

The GitHub user interface will default the option to the last option selected by the user for the current project. This solves the issue of not accidentally using the wrong default, since after the merge is done correctly for the first PR, subsequent merges will have the desired default.

This solution isn't perfect. If a user makes an intentional one-off merge of a different type, they will need to remember to set it back for their next merge, as the default will have changed to what was intended to be a one-off deviation from the norm.

M. Justin
  • 14,487
  • 7
  • 91
  • 130
  • 1
    I think github may have changed this behavior. The default for new repositories seems to be "Squash and merge". I have to click on the dropdown and select "Create a merge commit" each time. I have done this probably 20+ times on each repository and the default option remains as "Squash and merge" – aravindanve Oct 27 '20 at 03:36
  • 5
    It still works for me as described in the answer. However I am unsatisfied with this because very occasionally I do want a merge commit and then after that I always accidentally make at least one other on the next PR. I'd prefer to have an actual default setting on the repo. – Jeremy Nov 29 '21 at 14:47
  • @Jeremy Agreed, and I find myself in the same situation on occasion. – M. Justin Nov 29 '21 at 19:57
  • 1
    @Jeremy I've added a paragraph to the answer describing your concern – M. Justin Dec 16 '21 at 19:23
17

You can effectively make this the default for the repository in github by disallowing other types of merges. From the repository, click Settings, and then on the Options tab scroll down to "Merge Button". You can uncheck "Allow Merge Commits" and "Allow rebase merging", which leaves "Allow squash merging" as the only choice for merging pull requests in this repo.

Chris Riccio
  • 573
  • 3
  • 11
6

No.

There's currently no way to set default merge strategy on GitHub, and I didn't find any feature requests for it either. So I made a feature request for it here: https://github.com/github-community/community/discussions/20583

Please go vote and comment if you agree with the suggested feature(s)

Snailedlt
  • 460
  • 6
  • 14