If you’ve ever been surprised by the vi
editor opening when you’re writing a Git commit message in Git Bash, you’re not alone.
The vi
(or vim
) editor is powerful but can be unintuitive for beginners. The good news? You don’t need to master vi
to use Git effectively—you just need to know how to exit safely.
In this post, we’ll walk you through how to exit the vi
editor in Git Bash, especially when it shows up during Git operations like git commit
.
📝 Why Does vi
Open in Git Bash?
When you run:
git commit
Without the -m
flag, Git opens the default text editor (often vi
or vim
) to allow you to write a commit message.
In Git Bash on Windows, vi
is frequently the default editor. If you don’t know how to use it, getting stuck is frustrating.
🚪 How to Exit vi
Editor
If You Want to Save and Exit:
- Press
Esc
to ensure you’re not in insert mode. - Type:
:wq
Then pressEnter
.:
tellsvi
you’re entering a command.w
stands for “write” (save).q
stands for “quit”.
✅ This will save your changes and exit the editor.
If You Want to Exit Without Saving:
- Press
Esc
to leave insert mode. - Type:
:q!
Then pressEnter
.q!
means “quit without saving.”
🚫 This will discard any changes you’ve made.
🔄 Quick Summary of Commands
Action | Command |
---|---|
Save and Exit | :wq |
Exit Without Saving | :q! |
Save Only | :w |
Quit Only (if no changes) | :q |
🛠️ Optional: Change Default Git Editor
If you find vi
too cumbersome, you can change the default Git editor to something more user-friendly, like Notepad or VS Code.
Example: Set Notepad as Git Editor
git config --global core.editor "notepad"
Example: Set Visual Studio Code as Git Editor
git config --global core.editor "code --wait"
🧠 The
--wait
flag tells Git to wait until you close the file in VS Code before proceeding.
✅ Conclusion
The vi
editor may seem intimidating at first, but once you know the basics—especially how to exit—it becomes much more manageable. Whether you decide to learn more about it or switch to a simpler editor, you’re now in control of your Git experience.