79

How can I force git merge to use the default merge message instead of loading my editor with said message?

I have no editor listed in git config -l, so I'm not sure why it opens an editor.

Brad Koch
  • 19,267
  • 19
  • 110
  • 137
kjb
  • 3,035
  • 3
  • 23
  • 30

4 Answers4

95

Found the answer after some digging

EDIT: As per Mark's suggestion, this is the best way to do so:

git config --global core.mergeoptions --no-edit
kjb
  • 3,035
  • 3
  • 23
  • 30
  • 18
    Rather than edit `~/.gitconfig` directly, it might be safer to suggest using `git config` to do this, e.g. `git config --global core.mergeoptions --no-edit`, so that there's no chance of creating a malformed `~/.gitconfig`. – Mark Longair Oct 05 '12 at 22:04
  • 3
    This seems to work for `git merge`'s, but I'm still having an editor open up for `git pull`'s. Is there any way to disable the commit message for this as well? – LandonSchropp Nov 21 '13 at 07:29
  • 3
    I can't find any mention of `core.mergeoptions`, though it certainly applies to `branch.*.mergeoptions`. Does anyone know the supported versions for this? – cmbuckley Nov 27 '13 at 16:49
  • 4
    This doesn't work for me. Both merge and pull still bring up an editor on non-ff merges. Using git 1.7.10.4 – user2471887 Apr 30 '14 at 16:38
  • Interesting, this is NOT working for me with 1.7.12.4 (Apple Git-37). – user1978019 May 27 '14 at 16:48
  • I'm still having no issues and am now on a new computer, and currently running git version 2.2.1. For those not having any success, I'd imagine you have some sort of conflicting git option, or that you perhaps have multiple gitconfigs – kjb May 14 '15 at 20:38
  • 7
    A trip through the git source and release notes suggests that there is not now and never was a `core.mergeoptions`. There is, however, a `GIT_MERGE_AUTOEDIT=no` that was added to git 1.7.10 when `git merge` itself was changed to bring up the editor. There are also options available as `branch.*.mergeoptions`, as @cmbuckley noted. – torek Apr 22 '16 at 02:57
74

Use

export GIT_MERGE_AUTOEDIT=no

or

git merge --no-edit
ouah
  • 142,963
  • 15
  • 272
  • 331
  • This is almost what I wanted, but it forces you to type --no-edit every time. The solution I found changes the default behavior of `git merge` – kjb May 13 '13 at 01:46
  • Passing it directly to the merge command, as suggested here, is specially useful in a script that invokes git merge. You almost always want a script not to prompt the user. However, it'd be nice to know how to pass a custom message to `git merge`. Perhaps `git merge -m "message"` works but I haven't tried it yet. – Ernesto Feb 19 '15 at 20:24
  • 7
    For me, `export GIT_MERGE_AUTOEDIT=no` worked (for merges) when the accepted answer (`git config --global core.mergeoptions --no-edit`) did not. – Andrew Bennet Apr 19 '16 at 16:07
12

This is a new feature of Git, introduced in Git 1.7.10, to use the old one (don't provide a message on merge) put these two lines in your .bash_profile or .bashrc

GIT_MERGE_AUTOEDIT=no
export GIT_MERGE_AUTOEDIT
Orlando
  • 9,374
  • 3
  • 56
  • 53
0

try this

git merge --no-ff --no-edit -m "my custom merge message" somebranch

dawn360
  • 11
  • 3