The command line is stuck and unresponsive. What do I do?
The command line is a ✨ magical place ✨ where so many things are possible. As a developer, using the command line is part of our daily routine, whether you're launching a program, spinning up a server, running tests, installing dependencies, gathering information, manipulating files, and of course, using Git!!
Using the command line isn't without its pitfalls, however, and one of the most well-known sticking points is when you get, well, stuck (pun intended) in the command line.
You'll know when you're stuck if you can't get back to your command prompt. Your command line will just seem entirely unresponsive. This can be very frustrating and may lead you to quit the command line application altogether. While quitting the command line will work, it can also leave processes in an unfinished state, which isn't ideal.
Is there a better solution? Yes, of course, there is!!
The first thing you need to do is determine what kind of situation you are in. There are several reasons the command line can become "stuck," so our first order of business is narrowing down the possibilities.
Here are 3 of the most common scenarios:
1) You ran a command and it is just hanging. In other words, nothing is happening, you waited a few seconds, it's like your command line is dead in the water.
Solution:
Ctrl + c
Typing Ctrl + c will interrupt the "stuck" process and bring you back to the command prompt.
2) You ran
git log or
git diff and you can't get back to the prompt.
Solution:
q
Here you'll need to hit q to quit the log and get back to the command line. You can also hit the spacebar to scroll through more results (if any are available) before you hit q to return to your prompt.
3) You ran a command such as
git commit without the message (whoops) and Git opened up a text editor for you to enter the commit message. (This can also happen with git merge).
Solution:
If Git opened Nano for you, you'll want to hit
Ctrl + x to exit. Nano might ask you to confirm, if it does just follow the prompts.
If Git opened Vim (or Vi) for you, you will need to hit the
Esc key to enter command mode, and then type
:q! (all three characters, including the colon (:) are important).
Once you are back in the command line, you can run your commit or merge command again, but this time, make sure to include the -m flag and a message between quotes:
git commit -m "Your message here"
There you have it! Now you should be able to get back to your beloved command prompt whenever you like, and you and the command line can go back to resuming your cordial relationship.