macos – Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch

macos – Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch

Its not a Git error message, its the editor as git uses your default editor.

To solve this:

  1. press i (i for insert)
  2. write your merge message
  3. press esc (escape)
  4. write :wq (write & quit)
  5. then press enter

Actually its not an error! It means you should enter some message to mark this merge.

My OS is Ubuntu 14.04. If you use the same OS, you just need to do this as follows:

  1. Type some message

  2. CtrlCO

  3. Type the file name (such as Merge_feature01) and press Enter

  4. CtrlX to exit

Now if you go to .git and you will find the file Merge_feature01, thats the merge log actually.

macos – Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch

tl;dr ✨ Use an $EDITOR that you like! ✨

The fix is not to memorize cryptic commands, like in the accepted answer, but configuring Git to use an editor that you like and understand!

The underlying problem is that Git by default uses an editor that is too unintuitive to use for most people: Vim. This is because Vim is present everywhere, not because it is user friendly Now, dont get me wrong, I ❤️ Vim, and while you could set some time aside to learn Vim and try to understand why some people think Vim is the greatest editor in existence, there is a quicker way of fixing this problem 🙂

Its really as simple as configuring either of these options

  1. the git config setting core.editor (per project, or globally)
  2. the VISUAL or EDITOR environment variable (this works for other programs as well). Typically stuffing export VISUAL=vscode --wait into your .bashrc or similar config.

Ill cover the first option for a couple of popular editors, but GitHub has an excellent guide on this for many editors as well.

To use Atom

Straight from its docs, enter this in a terminal:

git config --global core.editor atom --wait

Git normally wait for the editor command to finish before progressing, but since Atom forks to a background process immediately, this wont work, unless you give it the --wait option. This makes it stay as a foreground process, just as we want.

To use Sublime Text

For the same reasons as in the Atom case, you need a special flag to signal to the process that it shouldnt fork to the background:

git config --global core.editor subl -n -w

To use Visual Studio Code

git config --global core.editor code --wait

Leave a Reply

Your email address will not be published.