865

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.

4
  • 5
    It appears that your GIT is configured to open a pre-configured template and that template is getting opened through default editor (vi/vim).
    – Shunya
    Commented Sep 30, 2013 at 9:26
  • 29
    Form me "Shift ZZ" solves the issue
    – papacico
    Commented Oct 24, 2018 at 10:46
  • Yeah it works for me as well, @papacico how does it work? Commented Jan 24, 2023 at 13:06
  • See also: stackoverflow.com/questions/11828270/how-do-i-exit-vim Commented Jan 25, 2023 at 22:06

10 Answers 10

2065

The commit message is from Git, but it is actually the editor that keeps you from quitting. This is because Git uses your default editor, which for a variety of reasons is usually set to vi (it might be something else on your OS, like pico).

To write a commit message and get out of VI, follow these steps:

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

You can also configure Git to use another editor to avoid having to use VI (or its close cousin VIM).

26
  • 27
    Ok, but this is assuming his editor is vi or vim. Commented Sep 30, 2013 at 3:18
  • 226
    that's hella complicated Commented Aug 21, 2014 at 22:32
  • 193
    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".
    – Josh Beam
    Commented May 20, 2015 at 22:17
  • 18
    To make life easier just follow step-4: write ":wq" then press enter
    – abbas
    Commented Jan 20, 2016 at 8:48
  • 148
    This might as well be ↑↑↓↓←→←→BA Commented Nov 4, 2016 at 7:42
81

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.

4
  • 17
    I wonder how someone would know this? It's so strange how this works. Thanks for answering this. Commented Sep 27, 2015 at 19:48
  • @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.
    – oligofren
    Commented Nov 10, 2017 at 12:46
  • What is the name of the editor that corresponds to this answer?
    – J. Mini
    Commented Jun 18, 2020 at 22:01
  • 1
    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.
    – tripleee
    Commented Aug 4, 2020 at 7:23
60

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"
3
  • 3
    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.
    – user264431
    Commented Jun 17, 2019 at 16:14
  • 1
    Use a CUA terminal editor like micro: micro-editor.github.io Commented Jun 18, 2021 at 2:32
  • "This is because Vim is present everywhere" - OSes may or may not come with vim (vi improved); it's classic vi that's everywhere. Also worth noting: defaulting to vi is not a git thing; git is simply using the OS default, which is commonly vi on Unices such as Linux and MacOS.
    – marcelm
    Commented Mar 9, 2023 at 13:37
45

Just Do,

CTRL + X

CTRL + C

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

2
  • This is if your default editor is "pico" or "nano" The above comments should be used if your default editor is vim.
    – JacKeown
    Commented Oct 17, 2019 at 17:07
  • For some reason my default editor was "nano" and I wasn't able to escape to command and write ":wq" as in vim, not sure if nano even supports this. ctrl + x and ctrl + c worked in my case, Ubuntu 20
    – Yash Patel
    Commented Feb 16, 2023 at 8:05
11

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.

2
  • 5
    lol this would definitely solve the OP's problem. git commit -m 'I did blah' Commented Feb 1, 2018 at 8:17
  • 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?
    – pglpm
    Commented Aug 2, 2018 at 11:36
10

Since your local repository is few commits ahead, git tries to merge your remote to your local repo. This can be handled via merge, but in your case, perhaps you are looking for rebase, i.e. add your commit to the top. You can do this with

git rebase or git pull --rebase

Here is a good article explaining the difference between git pull & git pull --rebase.

https://www.derekgourlay.com/blog/git-when-to-merge-vs-when-to-rebase/

1
  • 1
    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.
    – oligofren
    Commented Jun 18, 2021 at 11:09
3

In my case i got this message after merge. Decision: press esc, after this type :qa!

3
  • 1
    Is this really a helpful answer after over 6 years?...
    – mate00
    Commented Jul 14, 2020 at 13:25
  • 3
    I think so, because i because I ran into these yesterday
    – Vladimir
    Commented Jul 15, 2020 at 6:58
  • This is superfluous and covered by the accepted answer.
    – oligofren
    Commented Jun 18, 2021 at 11:07
1

In my case, I got this error while using IntelliJ (code editor - nano) on a Linux operating system. The way I solved it is by going through the following steps:

1. Push " Ctrl + X "
2. Type " Y " 
3. Hit "Enter" on your keyboard
1

I have the same error then I entred :qa! and I quit

0

can try this :

git pull --no-edit
2
  • This does not present an answer to the question: "How do I tell Git/Terminal I am done typing in my message?"
    – oligofren
    Commented Oct 7, 2022 at 12:47
  • It shows how to bypass the issue completely. IMO a legit answer.
    – HynekS
    Commented May 22, 2023 at 18:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.