63

Every time I run a git merge command it opens the text editor asking me to add an extra message.

How can I stop git from opening the editor & simply merging my branches? Because when it opens the editor it doesn't complete the merge, even if I add an extra message & save the file, the terminal just hangs on my git merge command.

Merge branch 'my-feature-branch' into main-development # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit. 
3
  • 4
    possible duplicate of Git merge doesn't use default merge message, opens editor with default message Commented Jul 7, 2014 at 11:09
  • 1
    "when it opens the editor it doesn't complete the merge, even if I add an extra message & save the file, the terminal just hangs on my git merge command." This is likely a bigger problem. When you do a non-merge commit do you get the same behaviour? Commented Jul 7, 2014 at 12:42
  • @dtech it's similar but not the same, same same but different :) Commented Jul 10, 2014 at 8:54

3 Answers 3

55

Use the --no-edit option, you can read about it in the documentation.

Note that using the default message is discuraged, since it provides no meaningful information about the changes introduced with this merge.


On a sidenote: To continue merging you probably have to close the editor.


If you have a git version prior to 1.7.8 there is still a way to achieve what you want by using the env command.

env GIT_EDITOR=: git merge <ref-you-want-to-merge> 

For easier usage you could create an alias.

git config --global alias.merge-no-edit '!env GIT_EDITOR=: git merge' 

Which then can be used using git merge-no-edit <ref-you-want-to-merge>.

Sign up to request clarification or add additional context in comments.

4 Comments

Do you know what version of git this was added to - we have CentOS 6 servers running git 1.7.1 and they do not support the --no-edit option.
@HamishDowner while it seems that there are no particular release notes which introduce the --no-edit option, it's mentioned in the 1.7.10 release notes saying that it can be used with "Git version 1.7.8 or newer". I'll edit my answer to include a solution for earlier versions.
Just found that the 1.7.8 release notes mention the --edit option, so that implies the --no-edit option.
The correct way is to do GIT_MERGE_AUTOEDIT=no git merge <branch> instead of unsetting GIT_EDITOR see this.
19

You can use

git merge --no-edit 

This is the man page :

--edit, -e, --no-edit Invoke an editor before committing successful mechanical merge to further edit the auto-generated merge message, so that the user can explain and justify the merge. The --no-edit option can be used to accept the auto-generated message (this is generally discouraged). The --edit (or -e) option is still useful if you are giving a draft message with the -m option from the command line and want to edit it in the editor.

Older scripts may depend on the historical behaviour of not allowing the user to edit the merge log message. They will see an editor opened when they run git merge. To make it easier to adjust such scripts to the updated behaviour, the environment variable GIT_MERGE_AUTOEDIT can be set to no at the beginning of them.

1 Comment

NOTE: To merge another branch or ref into the current branch, the branch name must come after the --no-edit option like this: git merge --no-edit origin/my-feautre-branch -- The order of these arguments matters. The editor will still open if passing the ref first.
17

Add the following line into your .bash_profile, .bashrc or .zshrc file:

export GIT_MERGE_AUTOEDIT=no 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.