Make VS Code Your Default Git Editor 📝

deadlybyte

Carl Saunders

Posted on February 18, 2020

Make VS Code Your Default Git Editor 📝

Recently I've found myself using the git command git commit --amend to change typos in my commit messages. By default the GNU nano text editor is used, which for me isn't a great experience and was starting to BUG me!

Default GNU nano editor for changing git message

GNU nano editor is used by default to change git commit message

I use VS Code daily and as I'm typing the git command in the built-in VS Code terminal, naturally I want to edit the commit message using the same editor. Well luckily you can configure this with a one liner.

Default VS Code As The Git Editor (Globally)

Type the following in the command prompt / bash shell.

git config --global core.editor "code --wait"
Enter fullscreen mode Exit fullscreen mode

Or, alternatively if you don't like typing too much then use.

git config --global core.editor "code -w"
Enter fullscreen mode Exit fullscreen mode

Note: The --wait or -w flag is crucial without this git won't know the editing has completed and in turn won't finish executing the git command.

See It Working!

Below is a gif showing VS Code as the default editor for git.

VS Code As The Default Git Editor

Working example of VS Code as the default git editor

Default VS Code As The Git Editor (Local Repo)

But wait there's more, if you don't want the change to happen globally you can set it locally for a git repository by using the flag --local.

git config --local core.editor "code -w"
Enter fullscreen mode Exit fullscreen mode

Revert Back To GNU nano (or default)

And if you prefer GNU nano and want to reset this to the default git editor, then run the following command.

git config --global --unset core.editor
Enter fullscreen mode Exit fullscreen mode

Note: If you set the editor locally and you want to reset then replace the --global flag with the --local flag instead.

💖 💪 🙅 🚩
deadlybyte
Carl Saunders

Posted on February 18, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related