I just executed a command $ git commit
and it opens a new editor. But I'm trying to close that new commit editor. How to do this? I'm using Git for Windows.

- 20,030
- 7
- 43
- 238

- 7,981
- 8
- 36
- 57
-
4not a complete answer, but one way to avoid the editor is to use the "-m" option. E.g. after $ git add
, then do $ git commit -m "my changes; I'm avoiding the editor!" – Quetzalcoatl Feb 24 '20 at 04:41 -
@Quetzalcoatl How do you enter new lines in `-m` ? – Koray Tugay Jul 23 '21 at 14:48
-
@KorayTugay: it's a good question but i don't know. generally, i would discourage long commit messages (e.g. with new lines) and encourage one sentence messages. brief and crisp commit messages tend to be more insightful here – Quetzalcoatl Jul 26 '21 at 20:47
-
@Koray Tugay after first double quotation marks, you press Enter and commit command does not end – lam vu Nguyen Jan 01 '23 at 03:44
14 Answers
Save the file in the editor. If it's Emacs: CTRLX CTRLS to save then CTRLX CTRLC to quit or if it's vi: :wq
Press esc
first to get out from editing. (in windows/vi)

- 2,396
- 23
- 30

- 14,112
- 6
- 42
- 57
-
4The user needs to close the editor in addition to saving the file, so for Emacs it's actually `Ctrl-X Ctrl-C`. – user4815162342 Nov 06 '12 at 05:43
-
2Updated... I knew that, but like most emacs commands, they're so ingrained in me that I forget what they are... I just do them. – tpg2114 Nov 06 '12 at 12:41
-
1
-
1thanks, on windows bash it is not clear that you must 1: exit and 2: save the changes – Juan Monsalve Nov 25 '19 at 15:15
-
-
On my window, I am surprised `Ctrlx-x` command is enough to abort commit. – Niyongabo Eric Sep 08 '20 at 04:11
-
what is emacs? The OP asks for windows... just ESC does not help, the answer is incomprehensible, don't know why it was marked as answer – serge Apr 19 '21 at 07:55
-
On Mac, the default editor is Vim, so press ESC first, then type :wq + ENTER – Lime莉茉 Sep 30 '21 at 17:47
-
-
Will not work for Windows Git Bash, which is the recommended way to use Git on Windows. – its.me.adam Mar 03 '23 at 23:31
Had troubles as well. On Linux I used Ctrl+X (and Y to confirm) and then I was back on the shell ready to pull/push.
On Windows GIT Bash Ctrl+X would do nothing and found out it works quite like vi/vim. Press i to enter inline insert mode. Type the description at the very top, press esc to exit insert mode, then type :x!
(now the cursor is at the bottom) and hit enter to save and exit.
If typing :q!
instead, will exit the editor without saving (and commit will be aborted)

- 22,976
- 9
- 42
- 68

- 4,579
- 2
- 16
- 22
-
30
-
9esc :x! - This isn't just undiscoverable its as if someone was playing hide and seek with functionality. – Tristan Jan 15 '19 at 17:09
-
-
After writing commit message, just press Esc Button and then write :wq or :wq! and then Enter to close the unix file.

- 9,564
- 146
- 81
- 122

- 1,185
- 1
- 10
- 7
-
7
-
! This reminded me of the University days, when we did some Unix vi editing things, after a long wrote some **`:wq`** commands – Irf Oct 03 '18 at 11:48
-
4
Better yet, configure the editor to something you are comfortable with (gedit as an example):
git config --global core.editor "gedit"
You can read the current configuration like this:
git config core.editor
You can also add the commit message from the command line.
git commit -m "blablabla"
and the editor will not be opened in the first place.

- 17,357
- 9
- 82
- 98
After git commit
command, you entered to the editor, so first hit i
then start typing. After committing your message hit Ctrl + c
then :wq

- 567
- 6
- 9
-
You should edit your commit message. Then follow above. Solution works for windows. – Shihab Uddin Aug 09 '21 at 12:19
Alternatives to Nano (might make your life easier):
On Windows, use notepad. In command prompt type:
git config core.editor notepad
On Ubuntu / Linux, use text editor (gedit). In terminal window type:
git config core.editor gedit

- 154
- 2
- 7
You Just clicking the key.
first press ESC + enter and then press :x + enter

- 53
- 1
- 3
I had this problem I received a ">" like prompt and I couldn't commit. I replace the " in the comment with ' and it works.
I hope this help someone!

- 1,598
- 19
- 25

- 126
- 1
- 6
-
1Aha! I had gotten stuck with this ">" prompt too. From reading your comment I figured out that since I had used an apostrophe in a contraction in my comment, the terminal was waiting for me to close out the quote! Finally I'm free! – Kevin Scharnhorst Jan 29 '20 at 18:42
As an alternative to 'save & quit', you can use git-commit's function git-commit-commit
, by default bound to C-c C-c. It will save the file and close it. Afterwards, you still have to close emacs with C-x C-c, as mentioned before. I am currently trying to find out how to make emacs quit automatically.

- 168
- 2
- 11
Not sure the key combination that gets you there to the > prompt but it is not a bash prompt that I know. I usually get it by accident. Ctrl+C (or D) gets me back to the $ prompt.

- 23
- 3
Note that if you're using Sublime as your commit editor, you need the -n -w
flags, otherwise git keeps thinking your commit message is empty and aborting.

- 4,296
- 6
- 44
- 65
I encountered the similar issue just in case this helps you.
When you hit the command git commit --amend
. It opens a default editor. Now, the question was how to close this. I have just resolved this so here it is if it helps:
press Ctrl + X
Press Y to select Yes
Press Ctrl + M + A (This command saves the commit message you are editing and brings you out of editor)
Try git log
command to verify your changes

- 4,552
- 14
- 29
- 49

- 53
- 1
- 11
Somehow my terminal on Mac opens Joe editor when git commit
. I had to press Ctrl + K H
to get to the help, this informed me to press Ctrl + K + X
to exit.

- 31
- 5