Git

How to Close the Git Commit Editor on Windows

Usually, when users make changes in their Git projects or code files on the local repository, it is required to update them on a remote repository. Also, commits are an essential part of a Git project’s timeline that can be milestones or snapshots along with a Git project timeline. The “$ git commit” command is used to create these commits to capture the state of the project.

This article will discuss closing the Git commit editor on Windows.

Note: In the following section, we will add a file to our selected repository, commit changes, and close the Git Commit editor.

How to Close the Git Commit Editor on Windows?

When users want to commit a project or files with a message to the remote repository, they can execute the “$ git commit” command on Git Bash. As a result, the text editor, configured as default at the time of Git Bash installation, opens up and allows you to make changes. However, sometimes users can not close the Git commit editor.

For this corresponding purpose, follow the below instructions.

Step 1: Open Git Bash
Open up the “Git Bash” on your system with the help of the “Startup” menu:

Step 2: Move to Directory
Execute the “cd” command and navigate to the Git repository:

$ cd "C:\Users\nazma\testing"

Step 3: Check Directory Status
Check the current status of the Git repository:

$ git status

Below output indicates that we have one untracked file named “5.file.txt” which needs to be added to the repository for commit:

Step 4: Add File
Add the untracked “5.file.txt” file into the Git repository using the below-provided command:

$ git add 5.file.txt:

According to the given output, our specified file is successfully added to the Git repository and ready for commit:

Step 5: Git Commit
Now, execute the “git commit” command to commit a message:

$ git commit

As a result, your default Git Commit Editor will open up. In our case, we selected “Notepad++” as the default Git commit editor. That’s why it is opened automatically:

Step 6: Commit Message
Now, specify a commit message at the top of the file which is open in the editor, then press “CTRL + S” to save changes and press the “Esc” key to close the Git Commit Editor:

Note: If you have “Notepad++” as the default editor, then the provided method will work. However, if you have configured any other editor, then check out the below-given list:

  • For closing the “vi” Git commit editor, type the “:wq” command, where “:” helps to enter in the command mode because “vi” is a mode-based editor, “w” is for writing and saving the added commit, and “q” is to exit. Press the “Enter” key after specifying the mentioned command. This operation will save the added commit message and closet the Git editor.
  • For the “Emacs” editor, press the “CTRL + X+ S” to save the changes, and again press the “CTRL + X + C” to exit the editor.

After exiting the editor, all changes will also be displayed in the Git Bash:

That’s all! We have offered the method of closing the Git commit editor on Windows.

Conclusion

If your Git default text editor is “Notepad++”, then after adding the commit message in the editor, press “CTRL + S” to save changes. After that, hit the “Esc” key to quit the editor. However, if you are using any other text editor such as “vi” editor, then type the “:wq” command and press the “Enter” key to close it. To quit the “Emacs” editor, first, save the changes by pressing the “CTRL + X+ S” key and then press the “CTRL + X + C” to exit the editor. This article illustrated the procedure of closing the Git commit editor on Windows.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.