git Editor Configurations
tl;dr
- There are two ways to set git editor:
git config
- the shell’s
GIT_EDITOR
environment variable
- The shell environment variable takes preference over the
git config
value.
I want to share how I debugged a git editor configuration issue where
an editor other than the one set in git config core.editor
. I will
walk through the situation and how I solved it.
By reading this, one will learn there is more than one way to configure the default editor for git and there is a configuration order. Next time you encounter an issue, here is another possible area to investigate.
This article will take about two minutes to read.
Introduction
Are you having problems with the Atom editor modifying your git commit
message? Not able to git commit --amend
because the editor just
opens up and the commit message template is not there?
I found this when pairing with a coworker and they use Atom as their default editor. Everyone on the team uses a different editor, it’s either great or hell. I embrace it as there’s always something to learn and it keeps me humble. This is a situation where I learned something unexpected because of a different editor.
This issue with the git commit message happened when I wanted to amend a previous git commit message on a coworker’s computer.
Executing git commit --amend
opened up atom
, her configured git
editor (in: git config core.editor
) but it would show nothing.
Searching around, I discovered the issue was the editor value, atom
--wait
is the correct parameter to use instead of just
atom
. tip
Setting git config core.editor='atom --wait'
should have changed
the situation, the problem still persisted when running git commit
--amend
Set it to something else!
I resorted to changing the git editor to vim
, something different. A
change of that level must work, right?
Well, when setting git config core.editor='vim'
, atom still opened
when executing: git commit --amend
.
HUH!?
(and the editor didn’t have the commit message!)
Why was atom
still launching, even when configuring the git editor
to be vim
?! The git editor value must be coming from somewhere
else! (Either that, or someone aliased vim
-> atom
, which now that
I think about it, would make great prank.)
I had a hunch that this issue was beyond just the git config
, as
changing the editor to vim
did not change anything and vim
was
really vim
.
Beyond git config
I looked at the environment variables set in the bash profile and noticed:
$ env
...
GIT_EDITOR=atom
...
Eureka! This would explain why changing the git config editor, atom
still launches!
When changing the GIT_EDITOR value to:
$ export GIT_EDITOR=vim
$ git commit --amend
vim
finally shows up with the git commit message to edit.
Lesson
There are two ways to configure the git editor through:
- The
git config
that controls all parts of git. - The environment variable:
GIT_EDITOR
that is part of the shell variables.
As someone that works with git, I never expected a shell environment
to override the git config
setting. Now I learned the order git
evaluates for its editor, even above the program’s own internal value.
Note: Configuring GIT_EDITOR='atom --wait'
also fixed the original
issue.