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

669,173

Solution 1

It's not a Git error message, it's 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

Solution 2

Actually it's 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", that's the merge log actually.

Solution 3

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, don't 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 :-)

It's 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.

I'll 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 won't 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 shouldn't fork to the background:

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

🤓 To use Visual Studio Code

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

Solution 4

Just Do,

CTRL + X

CTRL + C

It will ask you to save file, Press Y, then you are done.

Solution 5

Instead, you could git CtrlZ and retry the commit but this time add " -m " with a message in quotes after it, then it will commit without prompting you with that page.

Share:
669,173
bernie2436
Author by

bernie2436

Updated on July 08, 2022

Comments

  • bernie2436
    bernie2436 almost 2 years

    I am using Git. I did a pull from a remote repo and got an error message:

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

    I try to type a message and press Enter but nothing happens.

    How do I tell Git/Terminal I am done typing in my message?

    I am using Terminal on OS X.

  • Gabriele Petronella
    Gabriele Petronella over 10 years
    Ok, but this is assuming his editor is vi or vim.
  • Connor Leech
    Connor Leech over 9 years
    that's hella complicated
  • Ans
    Ans about 9 years
    I'm using Terminal for on Mac (Yosemite) and this solution worked for me.
  • Josh Beam
    Josh Beam almost 9 years
    If it helps anyone, the way you remember this is that "i" is for "insert", "esc" is the exit the insertion, and ":wq" is just "write" and "quit".
  • Adrian Carr
    Adrian Carr over 8 years
    I wonder how someone would know this? It's so strange how this works. Thanks for answering this.
  • abbas
    abbas over 8 years
    To make life easier just follow step-4: write ":wq" then press enter
  • joshmcode
    joshmcode over 7 years
    @JoshBeam ahhh, maybe now (following your memory suggestion) I can finally stop coming to this answer repeatedly!
  • Arno
    Arno over 7 years
    I'm seeing the same issue. Commit and push from box A, pull from box B Box B says that includes a merge so I include the message like in the answer above. Once I do so "git status" after that B says I'm ahead by 1 commit so the process repeats. I have to push from box B even though "git diff" shows there are no differences to be able to do a subsequent pull.
  • mfaani
    mfaani over 7 years
    @Wooble Why did this happen in the first place? I just did git merge master as always...
  • Cozzbie
    Cozzbie over 7 years
    This answer is still relevant till this moment.
  • Wesley Smith
    Wesley Smith over 7 years
    This might as well be ↑↑↓↓←→←→BA
  • David Douglas
    David Douglas about 7 years
    Or ":x" to eXit
  • Luke Smith
    Luke Smith about 7 years
    'Enter :wq'. This is without the doubt the single least intuitive thing that has ever been designed by anyone ever. How on earth would anyone work out how to do that??!!!!! Jeeezzzz
  • Ashraf Slamang
    Ashraf Slamang over 6 years
    To switch the default editor for git to nano run this command: git config --global core.editor "nano"
  • oligofren
    oligofren over 6 years
    @ScottyBlades why on earth should it? the question is tagged osx, and this answer concerns how Ubuntu sets up an entirely different setup for Git (using nano or pico), which is not applicable to the OS X setup. It is in no way generalizable and also doesn't provide insight into how it works, hence the comment left by @AdrianCarr. There are far better answers now.
  • James M. Lay
    James M. Lay over 6 years
    lol this would definitely solve the OP's problem. git commit -m 'I did blah'
  • Ram
    Ram about 6 years
    Could you please explain these 2 steps :- 1. press "i" 2. press "esc" 3. write ":wq" What is the meaning of these shortcuts.
  • Ram
    Ram about 6 years
    @Saad.elzwawy Working fine. But could you please explain each steps meaning. I just want to know in details.
  • Saad.elzwawy
    Saad.elzwawy about 6 years
    Hi, @Ram press "i" i: Insert to insert text message for your commit, press "esc" esc: escape after finish write mode, and wanna go out, write ":wq" wq: write-quite it write and save your message then quite vim, then press enter
  • TMOTTM
    TMOTTM almost 6 years
    Why is this appearing suddendly? I didn't have it on the last 10 commits.
  • Saad.elzwawy
    Saad.elzwawy almost 6 years
    @TMOTTM this happen when you merge with another branch, for example: suppose your current branch name is xx, and you want to merge it with yy, then your write : git pull origin yy ..... in this message will appear.
  • pglpm
    pglpm almost 6 years
    I have git version 1.7.11.4 on a linux terminal, and despite the fact that I give git commit -m "message" or git commit --message "message", still the editor pop ups from time to time, requesting a message. Does anybody knows why the "-m" switch is ignored?
  • user264431
    user264431 almost 5 years
    Vim doesn't take a month. it takes two days and you never forget as long as you keep a handy cheat sheet you'll need from time to time, at first.
  • oligofren
    oligofren almost 5 years
    @hipoglucido There is nothing that says you have to have to use Vim! Just configure Git to use a different editor; one you like. See my answer for how.
  • JacKeown
    JacKeown over 4 years
    This is if your default editor is "pico" or "nano" The above comments should be used if your default editor is vim.
  • Henry Thomas
    Henry Thomas almost 4 years
    You literally have to enter the launch codes just to commit... you should just be able to press enter and be done.
  • J. Mini
    J. Mini almost 4 years
    What is the name of the editor that corresponds to this answer?
  • mate00
    mate00 almost 4 years
    Is this really a helpful answer after over 6 years?...
  • Vladimir
    Vladimir almost 4 years
    I think so, because i because I ran into these yesterday
  • tripleee
    tripleee almost 4 years
    It looks vaguely like this assumes your editor is nano. It has an obnoxious bar across the bottom which tells you some of the keyboard shortcuts.
  • Eldrax
    Eldrax over 3 years
    For everyone confused: this sequence has nothing to do with Git. Git sometimes has to ask you for a commit message (try git commit without providing a message, and the same should happen), and it does so by opening the text editor set in Git as default. On Linux-based OSes, this is generally Vim: a text editor that focuses on doing stuff with minimal keystrokes. The instructions in this answer are keystrokes for writing the message, saving and exiting the editor. Agreed, it looks weird if you've never used Vim, but this weird-looking sequence really has nothing to do with Git.
  • Josh
    Josh about 3 years
    @WesleySmith I though so, this is like executing a Fatality on MK 2 in the 90s, except one wrong key, and the fatality end up on ourselves. Nevertheless this worked fine for me in Android Studio Terminal for Mac.
  • Gringo Suave
    Gringo Suave almost 3 years
    Use a CUA terminal editor like micro: micro-editor.github.io
  • oligofren
    oligofren almost 3 years
    This is superfluous and covered by the accepted answer.
  • oligofren
    oligofren almost 3 years
    This has nothing to do with this issue directly: "How do I tell Git/Terminal I am done typing in my message?". The user needs to set his editor in the global git config or set the EDITOR variable.
  • Alessandro Sassi
    Alessandro Sassi almost 3 years
    write ":wq" means that when you type ":" it starts typing in the lower line, there you will type "wq". it was not obvious for me
  • John Miller
    John Miller almost 3 years
    Can someone please explain why git is using vim at all? Are we going to be stuck in the stone ages for forever or are we going to replace these old, clunky designs with better, more intuitive systems?
  • oligofren
    oligofren over 2 years
    @JohnMiller That's not hard to answer at all. Git does not care what editor you use, but it needs to use something. What editor is present in every operating system you can think of? The ubuquitous answer on Unix-like operating systems is vi. Neither nano, micro, pico or emacs can say that. And a GUI editor would be a no go. That's why every programmer should know the basics. And since this is dead easy to configure for the user to use something else, it's much better to consult the user's preferences than to think of complicated per-operating system rules.