Change the default diff or commit editor for git


Git Commit Editor

If you want to change the default editor that is used when you diff or commit to git, you need to make use of the git config command to set the global value for core.editor

Example 1: To set the editor as vi (or vim)
% git config --global core.editor vi
Example 2: To set the editor as nano
% git config --global core.editor nano
Example 3: To set the editor as sublime
% git config --global core.editor "subl -n -w"
Example 4: To set the editor as visual studio code (vscode)
% git config --global core.editor "code -w"
Example 5: To set the editor as Nodepad++
% git config --global core.editor "C:/Program Files/Notepad++/notepad++.exe' -multiInst"
Example 6: To set the editor as Atom
% git config --global core.editor "atom -w"

Once you set your favorite editor, you will see that the commit command opens it up!


# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Changes to be committed:
#       new file:   a.txt
#
~                                                                                                    
~                                                                                                    
~                                                                                                    
~                                                                                                    
"/myproj/.git/COMMIT_EDITMSG" 8L, 206B                                             1,0-1  
Advertisements
Try Out Code2care Dev Tools:

Advertisements

Advertisements
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.