Git

How to Use the Editor of My Choice For Editing Commit Messages in Git?

The Git commit is an essential component of the Git project, which saves all tracked changes into local Git repositories so that they can later be accessed by remote repositories. To better understand this concept, most developers like to commit messages along with changes while working on the same project. As a result, the commit message makes it simple for developers to understand what other members did.

This tutorial will demonstrate the method to use the Git editor of choice for editing commit messages.

How to Use the Git Editor of Choice For Editing Commit Messages in Git

The default Git editor is selected during the Git installation. On the other hand, users can utilize the editor of their choice for editing Git commit messages, files, and many more.

To edit the commit message using your preferred Git editor, follow up on the mentioned instructions.

Step 1: Open Git Bash Terminal
Open the Git Bash terminal from the Start menu:

Step 2: Open Git Repository
Open the Git repository using the “cd” command:

$ cd "C:\Git\Test"

Step 3: Generate New File
Utilize the “touch” command to generate a new file:

$ touch Demofile.txt

Step 4: Add Untracked Changes to Tracking Index
After that, add the untracked file to the tracking index by executing the below command:

$ git add Demofile.txt

Check out the “git status” command to verify if the changes are added to the tracking index or not:

$ git status

You can see we have successfully added the file to the staging area:

Step 5: Commit Tracked Changes
Commit the tracked changes using the “git commit” command. Here, the option “–amend” is used to edit a commit in the default selected editor:

$ git commit --amend

It can be observed that the “Notepad” is opened by default to edit commits. Edit your message as we have edited “Demo file is saved”:

Step 6: Check Git Log
List down the Git repository log using the “git log” command to verify if the commit is added or not:

$ git log

It can be observed that we have successfully committed the tracked changes:

Step 7: Change Editor
Now, set the editor of your choice to edit the commit message. For instance, we have selected the “nano” editor:

$ git config --global core.editor "nano"

Step 8: Edit Commit Message in Your Preferred Editor
Again, use the “git commit –amend” command to modify the Git commit message in your preferred editor:

$ git commit --amend

Here, you can see we have successfully opened the “nano” editor for editing Git commit messages. Add the message and press the “Ctrl+S” button to save changes. After that, hit the “Ctrl+X” key to close the nano editor:

Again, check the Git logs to verify if the commit message is edited or not:

$ git log

We have shown you the method to edit the commit message in your preferred editor.

Conclusion

To edit the Git commit in the editor of your choice, first, open the Git local repository. Select the editor of your choice for editing the commit message using “$ git config –global core.editor < “Editor name”>” command. After that, edit the Git commit using the “git commit –amend” command in your preferred editor. This tutorial has elaborated on how to use the Git editor of choice for editing commit messages.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.