Why do I need an editor?...
While you can commit changes with a simple message using git commit -m "message", sometimes you need more detailed commit messages. If you want to do things like "amending" commits or rebasing branches you will also need an editor.
The default way
The default editor that opens for git is vim
. vim
is great for experienced users, but can be a complete pain for beginners and I have seen it often serving as a barrier for beginners learning git
.
It doesn't have to be this way! You can use whatever editor you like when using git
.
Using your preferred editor for Git Commit
One of the most common text editors is VSCode. To use VSCode you can run:
GIT_EDITOR="code --wait" git commit
To make this permanent, set it globally with:
git config --global core.editor "code --wait"
Now when you run git commit
VSCode should open. You can enter your commit message in that file, then simply save/close it.
Equally, when you run rebase commands the VSCode editor will open and will offer you a multitude of tools to help you rebase! Experiment with some of them and see what you like. You may like the GUI tools with drag/drop options (personally, I prefer the simplest vim
approach, but that's just me!).
If you hit problems complaining about code
when you run git commit
, it might be because you haven't installed code
on the command line. Make sure to hit cmd + shift + p
, type Install 'code' command in PATH
, then hit Enter
.
Sorted! Have fun.