Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Git Basics Getting Started With Git Committing Changes

Ian Mackenzie
Ian Mackenzie
11,062 Points

Can't escape commit stage

I'm not sure if I'm using Nano but I'm stuck in the commit stage and can't get out of it. I'm on a Mac and I've tried Control + x but no go.

I'm using windows and can't seem to get out of the commit stage. Not sure what I'm doing wrong.

Ian Mackenzie
Ian Mackenzie
11,062 Points

Try hitting q on your keyboard, or read the answer provided by Jordan below.

2 Answers

You're in "Vi" mode, most likely. If you would like to edit in Vi mode, type "i" to go into insert mode. To leave insert mode, hit ESC. If you are finished and would like to save and quit, type ":wq<enter>" (type everything inside the quotes and hit the enter key when finished). The "w" and "q" stand for "write, quit".

To avoid this in the future, make sure when you commit, you put a comment. The reason why Vi was opened is because you can't commit something without putting a comment explaining the reasoning behind your commit. You can do this by typing:

git add <file-name> ( if you just type a period, it'll commit the entire folder the terminal or command prompt window is CD'd to. (Ex. git add . )
git commit -m "Commit comment would go here"
git push
Ian Mackenzie
Ian Mackenzie
11,062 Points

That was the case. I was in insert mode. I'll use the -m in future. Thanks for your help.

Chris Shaw
Chris Shaw
26,676 Points

Hi Ian,

GIT can be a bit tricky as by default it uses vim as the editor, to get out of the commit message simply press the colon : key which will activate the command area in the bottom left corner followed by the letter q which will save the message and quit the vim instance.

To save yourself some trouble you can change the default editor through the global GIT config, see the below link for help with that.

http://stackoverflow.com/questions/2596805/how-do-i-make-git-use-the-editor-of-my-choice-for-commits

Hope that helps.

Ian Mackenzie
Ian Mackenzie
11,062 Points

Hi Chris,

That didn't help me. I'm using Oh-my-zsh is that different? I've just quit the terminal to get out. I'll change my editor to use my editor of choice.

Chris Shaw
Chris Shaw
26,676 Points

oh-my-zsh is just an extension of the default /bin/bash environment and then some, I used it on my MacBook and don't have any issues with it. In saying that it sounds like you may have been stuck in something else, if you get stuck again post a screenshot as it might be something even more simple but in general commits are usually tied to vim.

Ian Mackenzie
Ian Mackenzie
11,062 Points

Thanks Chris, jordansportfolio just helped me out as I was in edit mode as I had not used -m with my commit.

Chris Shaw
Chris Shaw
26,676 Points

Glad you got it sorted, I'm vim illiterate so the "basic do something" and quit commands are about all I know :smiles: