31

I'm learning using Git on an OS X Terminal. It seems really easy. But I can't handle just one problem: When I try to merge two branches, for example "myTestBranch" into "master" this program covers the terminal and shows me a new view where I should write the merge message. And then, I don't know how to do "Enter", save the merge message and then come back to the main terminal view where I can continue working.

Does anyone know, how does it work?

What I see, when i try to merge

3
  • 3
    That is the vi or vim editor. You can get out of it by typing :q<enter>. You either need to learn vi (which is admittedly on the more difficult side) or define $EDITOR to be something friendlier, such as nano. Commented Nov 3, 2015 at 17:08
  • That's what I said, either vi or vim. Either way, either learn how to use, or else set your shell environment to use a different editor using the $EDITOR variable. nano is very simple to use and helpfully shows you what ctrl-keys you can press to exit, save, etc. Commented Nov 3, 2015 at 17:17
  • 1
    You should also look at the core.editor configuration option in git config (e.g. see stackoverflow.com/questions/6435246/…) Commented Nov 3, 2015 at 17:39

2 Answers 2

56

If you haven't change the default git's editor, that "new view" is the Vi program.

To save your commit message using Vi, follow the next steps:

  1. Type i
  2. Write your message
  3. Type the ESC key
  4. Type :wq
  5. DONE! :D

Typing :q, step 4, is not enough beacuse just means QUIT without saving. That's why you need :wq, which means WRITE and QUIT.

You can write your commit message using your favourite editor(vim, emacs, etc.). To achieve this, you can use configuration parameter or environment variables, listed in order:

  1. GIT_EDITOR environment variable
  2. core.editor configuration option
  3. VISUAL environment variable
  4. EDITOR environment variable

Using the configuration option type something like this:

$git config --global core.editor "nano"

Or if you want to use enviroment variables, add something like this to your .bash_profile

$export GIT_EDITOR="PATH/TO/YOUR/EDITOR"
Sign up to request clarification or add additional context in comments.

Comments

16

By default Git will open Vim as editor.

You basically need to type 'I' to start editing. After that ESC and type :q to quit or :w to save the file. You can also combine them: :wq to save and exit Vim.

For more information about Vim check the official documentation

To change Vim for any other editor check the Git Environment Variables or older posts with a similar question: How do I make Git use the editor of my choice for commits?

2 Comments

It's pretty quirky to learn but there are games that help.
Thank you very much, you helped me a lot :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.