(last updated on )
It probably happens to me once or twice a week. I try to get the current repository’s status, the log, or the contents of some specific commit when I’m greeted with a familiar error message.
$ git git status git: 'git' is not a git command. See 'git --help'. The most similar command is init
It’s self-explanitory enough for me to understand what happened immediately. I typed “git” in my terminal. Then I got distracted. I needed to look something up, think about which message I was going to use, or go out to lunch. When I come back I instinctively type “git status”, forgetting the first part of the command was already there.
I pause while git’s belittling tone rings in my ears.
“‘git’ is not a git command.”
Defeated, I press ↑, hold ⌥ while double-tapping ←, then ⌫ four times and ⏎, to get the result I wanted.
$ git status On branch master nothing to commit, working tree clean
$ git config --global alias.git '!git'
git as a subcommand alias1, a command is run whenever you execute
git git. Using an exclamation mark to the beginning of the alias’ value, git will run any command instead of just it’s own subcommands. In this case it’s aliased to
git git will be converted to
Using this alias,
$ git git status will now automatically convert to
$ git status.2
$ git git status On branch master nothing to commit, working tree clean
Now, git is a git command.