How do I make git use the editor of my choice for editing commit messages?

Question

How do I globally configure git to use a particular editor (e.g. vim) for commit messages?

Answer

Setting the default editor for Git

Pick one:

  • Set core.editor in your Git config:

    git config --global core.editor "vim"
    
  • Set the GIT_EDITOR environment variable:

    export GIT_EDITOR=vim
    

Setting the default editor for all programs

Set the standardized VISUAL and EDITOR environment variables*:

export VISUAL=vim
export EDITOR="$VISUAL"

NOTE: Setting both is not necessarily needed, but some programs may not use the more-correct VISUAL. See VISUAL vs. EDITOR.


Fixing compatibility issues

Some editors require a --wait flag, or they will open a blank page. For example:

  • Sublime Text (if correctly set up; or use the full path to the executable in place of subl):

    export VISUAL="subl --wait"
    
  • VS Code (after adding the shell command):

    export VISUAL="code --wait"
    

How can I deal with this Git warning? "Pulling without specifying how to reconcile divergent branches is discouraged"

If I fork someone else's private Github repo into my account, is it going to appear in my account as a public repo?