107

Company policy is to use --no-ff for merge commits. I personally like to adjust merge log messages so I use --no-commit. Plus I like to actually compile and test before I let the commit go.

How do I make --no-ff and --no-commit the default for me for all branches?

(and I've learned in the years since asking this, I almost always am happy with the commit, so it is simpler to allow it to commit by default and so long as I amend or otherwise fix things up before doing a push things are all good...)

Stripes
  • 4,161
  • 2
  • 25
  • 29
  • older related: http://stackoverflow.com/questions/2500296/can-i-make-fast-forwarding-be-off-by-default-in-git – cregox May 16 '12 at 17:02

4 Answers4

131

Put this in $HOME/.gitconfig:

[merge]
    ff = no
    commit = no

You can use git-config to do this:

  git config --global merge.commit no
  git config --global merge.ff no
William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • 3
    Are you sure this works? It does not for me, I had to use either `branch.master.mergeoptions="--no-ff"`, or `merge.ff="no"` (see answer below) – gaizka May 17 '12 at 10:30
  • @gaizka Indeed, in 1.7.2 and in 1.7.7.2 it does not work. I'll try to get some time later to check older versions. – William Pursell May 17 '12 at 14:21
  • @Stripes using the git config command, it puts it in [merge], not [core] – Tisch Jan 13 '16 at 11:19
  • 2
    This does not work for me. Maybe git does not even has merge.commit option, see [git-merge-with-no-commit-as-default](https://stackoverflow.com/questions/70615355/git-merge-with-no-commit-as-default) – Liu Hao Dec 14 '22 at 07:20
  • 1
    No, [there has never been a merge.commit config variable](https://stackoverflow.com/a/70617448/1824182), it's just that `git config` will allow the user to set any random text as a variable name (on the off chance some other software tool uses it). – Ti Strga Jan 27 '23 at 17:46
  • Is this still up-to-date ? It doesn't work for me. I can find no mention of a similar configuration variable in more recent versions of Git. – Charles Feb 24 '23 at 10:21
  • @Charles, as the previous comments pointed out, `merge.commit` doesn't do anything, but see [here](https://git-scm.com/docs/git-merge/#Documentation/git-merge.txt-mergeff) for `merge.ff` – irowe Apr 25 '23 at 19:45
64

To make --no-ff --no-commit the default merge behavior, set the options to no using:

git config --global merge.ff no
git config --global merge.commit no

However, the problem with this is that git pull = git fetch + git merge. So whenever you pull from the remote server, you'd be creating an ugly merge commit when a simple fast-forward would be warranted. To solve this, set pull.ff to yes:

git config --global pull.ff yes
Jian
  • 10,320
  • 7
  • 38
  • 43
  • 18
    While this is true when using mergeoptions, it should be noted that if you're using `merge.ff` instead then it doesn't do this - it only affects explicit merges, while pulls still do the desired fast forward. – Nick Sep 12 '12 at 11:54
  • 4
    When I use `merge.ff = no`, `git pull` creates merge commits. – Matt McClure May 22 '13 at 13:01
  • 4
    to solve this you should use `git pull --rebase` (http://git-scm.com/docs/git-pull) or configure `branch.autosetuprebase` (http://git-scm.com/docs/git-config.html) – Cybot Jun 24 '13 at 11:12
  • 9
    or use `pull.ff = yes` – gabeio Jun 03 '15 at 05:44
  • Is this still up-to-date ? It doesn't work for me. I can find no mention of a similar configuration variable in more recent versions of Git. – Charles Feb 24 '23 at 10:21
22

As of version 1.7.6 of git, you should use

git config [--global] merge.ff no

to "force" using --no-ff in every merge.

Default behaviour is

git config [--global] merge.ff yes

And with

git config [--global] merge.ff only

it will refuse non-fast-forward merges

gaizka
  • 574
  • 5
  • 5
  • Is this still up-to-date ? It doesn't work for me. I can find no mention of a similar configuration variable in more recent versions of Git. – Charles Feb 24 '23 at 10:21
14

According to manual, you should use

$ git config [--global] merge.ff false

to set no-fast-forward option by default for all branches with git-config utility.

alexglue
  • 1,292
  • 12
  • 18
  • Is this still up-to-date ? It doesn't work for me. I can find no mention of a similar configuration variable in more recent versions of Git. – Charles Feb 24 '23 at 10:22