gitmergeconfigcommit

git merge with --no-commit as default


I am trying to set git merge --no-ff --no-commit as a default behaviour for merge.

Now I have read below questions:

How do I make git merge's default be --no-ff --no-commit?

Git: Default "no commit" merge behaviour for all branches?

Following those answers, I added below to global config:

[merge]
    tool = winmerge
    ff = false
    commit = false

After adding new configurations --no-ff works correctly, but it still automatically commits. Then I searched for tried merge-documentation page:

https://git-scm.com/docs/merge-config/2.18.0

There is merge.ff entry but not merge.commit. I'm currently using git version 2.29.2.windows.2.

I added --no-commit to local config mergeoptions for a workaround:

[branch "master"]
    mergeoptions = --no-commit

It works for now, but I would like to have that behaviour default for all projects and branches on my pc.

So my questions are below:

  1. Does merge.commit config really exist? If it is version problem, which version would allow this?
  2. If merge.commit is not available, what would be the alternative?

Solution

  • There is no merge.commit option: see the source code, where you can see which options are handled, and observe the lack of a merge.commit option. There was no such option in 2014 either (clone and inspect the Git source to verify this, if you like).

    The merge.ff option has been around since then, but merge.commit has, as far as I can tell, never existed. You can of course run a command other than git merge to start merging, and by doing that, you can make this command supply --no-commit as an explicit argument. Note, however, that you cannot alias Git built-ins, so there is no way to make a Git alias that inserts --no-commit when you run git merge. Run git mymerge and make that a Git alias, or run mymerge and make that a shell alias, but do not run git merge.

    (Your other option is of course to set branch.name.mergeoptions for every branch name.)