159

Recently, following any git pull, git has started spawning my text editor, and asking for a merge commit message. A commit message is already pre-filled, and I just have to save and close the window to complete the pull.

In the past, it would do the merge silently, with a standard commit message (along the lines of Merge branch 'dev' of remote.com:/repo into dev).

I recently updated git to version 1.7.11.3 (via homebrew), but can't think of anything else I might have done to change this behavior. Is this a setting, or is there otherwise some way of getting back to the way it was?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
shanebonham
  • 2,219
  • 2
  • 18
  • 19

3 Answers3

170

In git 1.7.10, the git developers decided merge commits could be made too easily. As explained in this blog post, forcing the interactive commit message behavior should make those commit messages more detailed and could reduce the overall frequency of unnecessary merges.

You can use the --no-edit flag to avoid this behavior, but, well, don't. Merge commits, like any commits to history, should be well constructed. Your history should be nothing but useful.

Christopher
  • 42,720
  • 11
  • 81
  • 99
  • 61
    Thanks for the help. I disagree that merge commits should always be descriptive though. The reason I looked this up is because automatic merges whenever I pull are asking me to explain why the merge is necessary, which quickly becomes unreasonable since it's even doing that when I don't have any changes. – Brian Nov 13 '12 at 15:57
  • 11
    This is also a useful resource for avoiding this behavior: http://longair.net/blog/2009/04/16/git-fetch-and-merge/ You should be avoiding `git pull`; use `git merge --ff-only` if you are just trying to update and you don't think you have any local changes; use `git merge --no-ff` if you are actually trying to merge a branch in. – Glyph Apr 24 '13 at 22:00
  • 8
    Is there a config flag to turn this off? It's annoying to have to type --no-edit every time. – LandonSchropp Jun 20 '13 at 01:22
  • While we're at it- opposite question, I'm using an older Git version (1.7.0.4) on one machine, can I set 1.7.10's behaviour as the default? – Kos Aug 21 '13 at 15:26
  • @Kos: Hmmm. Try git merge's `--no-ff` flag. That'll force a merge commit with every merge, which might get you what you want. You can then "make it permanent" by setting `git config --global merge.ff false`. `man git-config` should get you more details. I've no easy way to regress to v1.7.0.4 on this machine and thus can't test this suggestion. – Christopher Aug 21 '13 at 18:18
  • I always pull with --ff-only and normally only merge when I want --no-ff, but I asked about a setting "ask for a commit message before every merge". – Kos Aug 22 '13 at 06:54
  • @Kos: Ah, unfortunately I'm not sure of a way to get what you want in `1.7.0.4`. Someone else might though. It'd make a decent SO question on its own. – Christopher Aug 22 '13 at 15:28
  • How do I edit the text and dismiss this edit window on a mac terminal session. Seems whatever I do I have to quit out and re-do the commit manually. – Sean Dec 12 '13 at 06:43
  • 3
    @SeanCoetzee: It depends on your `$EDITOR` setting, but if you're using git out of the box on OSX it's probably a program called ['vi'](http://www.cs.colostate.edu/helpdocs/vi.html). Type `i` to enter "INSERT" mode; type your message. You can then save and quit by hitting `ESC` and then typing `:wq`. – Christopher Dec 12 '13 at 22:02
  • If your `git merge` command is in a script for automation, consider using `git merge -m` flag to supply useful information for the commit logs. – broc.seib Jul 16 '14 at 18:36
  • You're correct as to why, but the admonishing to keep putting up with this annoyance is unhelpful - downvoted for that. I'll switch it to an upvote if you remove the brow-beating. – Chris Moschini Nov 03 '20 at 19:40
  • Just a note: --no-edit belongs right after `pull` keyword, like this: `git pull --no-edit update master`. Lost an hour figuring why it does not work. – aleskva May 08 '21 at 10:15
69

To create a shortcut for future use, either:-

Edit your ~/.gitconfig with the following:

[core]
    mergeoptions = --no-edit

Or execute the following in Terminal

git config --global core.mergeoptions --no-edit

Dallas Clark
  • 4,064
  • 3
  • 30
  • 36
14

First, take heed of the warnings in Christopher's answer above.

Then, if you still want to disable automatic merge commit message editing, set this environment variable:

    GIT_MERGE_AUTOEDIT=no

This environment variable and its "no" setting are documented on the git merge doc page. It is recommended to use it only in scripts that need to merge non-interactively, but of course it can be set as part of your shell environment to make its effects more permanent.

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
emackey
  • 11,818
  • 2
  • 38
  • 58
  • Can you explain how this might be different than using the `--no-edit` flag? – Alexander Mills Aug 31 '18 at 23:58
  • 2
    I don't know of a functional difference, but the convenience factor makes it worthwhile. The `--no-edit` flag has to be repeated on the command line with each usage, as it does not appear to work in the settings as described in Dallas Clark's answer here. Setting the environment variable is the only way I know to make this setting stick. – emackey Sep 01 '18 at 15:33