97

I'm in the process of learning github on mac (command-line) and whenever I do git pull origin master i get this

# 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.
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
".git/MERGE_MSG" 7L, 293C

the terminal seems to lock up and doesn't allow me to enter anything immediately, then when it finally does allow me to enter text it seems like it doesn't recognize git commands.

Is this a bug in git or am i missing something?

zero
  • 2,999
  • 9
  • 42
  • 67

8 Answers8

232

You're in the text editor, vim! It's a modal text editor, so you would need to:

  1. Press i to enter insert mode.
  2. Now you can type your message, as if you were in a normal (non-modal) text editor.
  3. Press esc to go back to command mode.
  4. Then type :w followed by enter to save.
  5. Finally :q followed by enter to quit.
Muhammad Nabeel Arif
  • 19,140
  • 8
  • 51
  • 70
ceyko
  • 4,822
  • 1
  • 18
  • 23
  • 5
    It's great that git just assumes everyone knows vim. – user124384 Aug 29 '15 at 01:00
  • 2
    @user124384 Git tries to use your `$EDITOR` environment variable, but falls back to `vi` if it can't find one. You can configure the fallback via git config's `core.editor`. See https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#coreeditor-mjjck – ceyko Aug 31 '15 at 20:07
  • where I can type `i` ? – Val Do Oct 06 '15 at 12:40
  • 1
    @val-kharitonashvili On a querty keyboard, it's adjacent to `u` and `o` ;) But really, as long as the terminal has focus, it should work. – ceyko Oct 06 '15 at 19:44
  • 1
    Why does this even happen? I have always been doing `git merge master` and in the past 2 days, I'm seeing this... – mfaani Sep 09 '16 at 15:47
  • this saved me a lot. Thank you – zaman Jul 20 '22 at 08:37
19

Make it simple.

Type :wq and enter

abbas
  • 6,453
  • 2
  • 40
  • 36
2

The editor looks like to be vim according to your descriptions. This console is simply telling you to write some message for the commit you want to make, and it is compulsory as it does.

  • Just type i and you'll go in the -- INTER -- mode, now you can write your comments.

  • After you have done writing, press esc key in your keyboard and you'll go to command mode. (see on the bottom of the console)

  • Now save changes by writing :w followed by pressing enter key

Writing <code>:w</code> command

  • You can quit now by writing :q followed by pressing enter key

Writing <code>:q</code> command

  • Hurray! Finally you're back to the main console.
OM Bharatiya
  • 1,840
  • 14
  • 23
2

More simple is first ESC and then : x (lowercase).

Ariel Ruiz
  • 163
  • 2
  • 6
1

Run this command

git config --global core.editor "gedit"

Add your message in this file and save it. Go back pull now.

legoscia
  • 39,593
  • 22
  • 116
  • 167
Ayman Elshehawy
  • 2,746
  • 23
  • 21
0

I fixed this problem by executing following steps

  1. Remove #MERGE_MSG#

    rm .git/\#MERGE_MSG#

  2. Remove MERGE_HEAD

    rm .git/MERGE_HEAD

Additionally, I explicitly set git's editor to an editor that I am familiar with vim (you can set nano)

`git config --global core.editor "vim"`
Lukasz Dynowski
  • 11,169
  • 9
  • 81
  • 124
0

You can do git checkout --merge yourbranch

A three-way merge between the current branch, your working tree contents, and the new branch is done, and you will be on the new branch.

mdeora
  • 4,152
  • 2
  • 19
  • 29
0

Problems usually happen when we misspell something.
It is more likely this command you are interested in:

git commit -m "message"

if there was a problem, it might say something like

Your branch and 'origin/master' have diverged,
and have 2 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

and use:

git pull

which should lead to:

Already up-to-date.

Then it is good to check:

git status

and try pushing again:

git push
Erik Rybalkin
  • 1,143
  • 12
  • 21