614

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.

pkamb
  • 26,648
  • 20
  • 124
  • 157
bernie2436
  • 18,811
  • 41
  • 130
  • 228

9 Answers9

1450

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
Sajid Zeb
  • 1,339
  • 15
  • 29
Saad.elzwawy
  • 14,714
  • 1
  • 11
  • 16
  • 19
    Ok, but this is assuming his editor is `vi` or `vim`. – Gabriele Petronella Sep 30 '13 at 03:18
  • 158
    that's hella complicated – Connor Leech Aug 21 '14 at 22:32
  • I'm using Terminal for on Mac (Yosemite) and this solution worked for me. – Ans Mar 11 '15 at 15:17
  • 169
    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 May 20 '15 at 22:17
  • 5
    To make life easier just follow step-4: write ":wq" then press enter – abbas Jan 20 '16 at 08:48
  • 3
    How the heck am I supposed to remember that :D – Vlady Veselinov May 18 '16 at 04:36
  • 3
    @JoshBeam ahhh, maybe now (following your memory suggestion) I can finally stop coming to this answer repeatedly! – joshmcode Aug 30 '16 at 02:14
  • 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. – Arno Sep 06 '16 at 14:55
  • 2
    @Wooble Why did this happen in the first place? I just did `git merge master` as always... – Honey Sep 08 '16 at 22:44
  • 1
    This answer is still relevant till this moment. – Cozzbie Sep 21 '16 at 11:14
  • 107
    This might as well be ↑↑↓↓←→←→BA – Wesley Smith Nov 04 '16 at 07:42
  • 1
    Or ":x" to eXit – David Douglas Apr 18 '17 at 10:59
  • 5
    '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 – Luke Smith May 17 '17 at 10:17
  • 3
    To switch the default editor for git to `nano` run this command: `git config --global core.editor "nano"` – Ashraf Slamang Oct 17 '17 at 13:29
  • Could you please explain these 2 steps :- 1. press "i" 2. press "esc" 3. write ":wq" What is the meaning of these shortcuts. – Ram Apr 25 '18 at 07:19
  • 1
    @Saad.elzwawy Working fine. But could you please explain each steps meaning. I just want to know in details. – Ram Apr 25 '18 at 07:35
  • 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 – Saad.elzwawy Apr 25 '18 at 12:27
  • Why is this appearing suddendly? I didn't have it on the last 10 commits. – TMOTTM Jul 25 '18 at 10:31
  • @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. – Saad.elzwawy Jul 25 '18 at 13:59
  • 1
    @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](https://stackoverflow.com/a/47223056/200987) for how. – oligofren Jul 02 '19 at 07:33
  • 1
    You literally have to enter the launch codes just to commit... you should just be able to press enter and be done. – Henry Thomas May 29 '20 at 17:08
  • I hate this as much as I'm fascinated by it. – Tiago César Oliveira Nov 18 '20 at 22:28
  • 1
    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. – Eldrax Jan 14 '21 at 11:15
  • very comfortable! – Andrea Scarafoni Feb 10 '21 at 17:17
  • 1
    @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. – Josh Mar 18 '21 at 09:28
53

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.

K.Dᴀᴠɪs
  • 9,384
  • 11
  • 31
  • 39
xiaohu Wang
  • 631
  • 6
  • 4
  • 8
    I wonder how someone would know this? It's so strange how this works. Thanks for answering this. – Adrian Carr Sep 27 '15 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 Nov 10 '17 at 12:46
  • What is the name of the editor that corresponds to this answer? – J. Mini Jun 18 '20 at 22:01
  • 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 Aug 04 '20 at 07:23
34

tl;dr Set the editor to something nicer, like Sublime or Atom

Here nice is used in the meaning of an editor you like or find more user friendly.

The underlying problem is that Git by default uses an editor that is too unintuitive to use for most people: Vim. Now, don't get me wrong, I love Vim, and while you could set some time aside (like a month) 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 :-)

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! 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)

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, but since Atom forks to a background process immediately, this won't work, unless you give it the --wait option.

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"

oligofren
  • 15,352
  • 12
  • 75
  • 134
  • 2
    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 Jun 17 '19 at 16:14
32

Just Do,

CTRL + X

CTRL + C

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

Developer Guy
  • 2,012
  • 6
  • 17
  • 30
Mandeep Singh
  • 651
  • 7
  • 12
  • This is if your default editor is "pico" or "nano" The above comments should be used if your default editor is vim. – JacKeown Oct 17 '19 at 17:07
7

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.

K.Dᴀᴠɪs
  • 9,384
  • 11
  • 31
  • 39
hgrov52
  • 79
  • 1
  • 4
  • 3
    lol this would definitely solve the OP's problem. `git commit -m 'I did blah'` – James M. Lay Feb 01 '18 at 08: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 Aug 02 '18 at 11:36
7

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/

Ankush Jain
  • 3,773
  • 3
  • 21
  • 42
2

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

Vladimir
  • 79
  • 4
0

I found the error because i was new to git you must check whether you have entered the correct syntax

i made a mistake and wrote git commit

and got the same error

use git commit -m 'some comment'

and you wont be seeing the page with

0

I had the same issue when I was using GIT bash to merge master branch in to my feature branch. I followed the following steps to overcome this.

  1. press 'i' (To insert a merge message)
  2. write your merge message
  3. press esc button (To go back)
  4. write ':wq' (write & quit)
  5. then press enter
Chamila Maddumage
  • 1,956
  • 1
  • 17
  • 32