How to Close the Git Commit Editor on Windows

John Wachira Feb 02, 2024
How to Close the Git Commit Editor on Windows

In this article, we will discuss how we can exit the Git commit editor. It can be a bit tricky, especially if you are new to Git bash.

Let us see how we can exit the editor on Windows.

Close the Git Commit Editor on Windows

We will look at the typical commit flow on Git to make it easier to understand. From the example below, we can see the several untracked files we have by running the git status command.

pc@JOHN MINGW64 ~/Documents/GitHub/Delftscopetech (main)
$ git status
On branch main
Your branch is ahead of 'origin/main' by 3 commits.
  (use "git push" to publish your local commits)
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore~
        Example Code 2
        Example Code 2.php
        Example Code 3.php
        Example code 1.php
        downloadpdf.php
        htmllinkpdf.html
nothing added to commit but untracked files present (use "git add" to track)

Let us add the downloadpdf.php file and commit the changes. We run the code below to add:

$ git add downloadpdf.php

To commit, we run the command below:

$ git commit

Upon running the git commit command, the commit editor will pop up, as shown below:

exit git commit message editor 1

Follow these steps to save your commit and exit the editor.

  1. A newly opened editor is usually in normal mode. Use i to switch to the insert mode.

  2. On the first line, write your commit message and hit esc to switch back to normal mode.

  3. Type :wq to save and exit the editor.

    exit git commit message editor 2

  4. Hit enter to return to the normal terminal window.

    exit git commit message editor 3

It is that simple to exit the editor on Windows. This method works for vi and vim editors.

For those using the Emacs editor, use Ctrl+X Ctrl+S to save and Ctrl+X Ctrl+C to quit the editor.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git Commit