git = !git
The git alias in the title might look confusing at first, but it's a very nice little "hack" to make git more forgiving.
I usually tab from my editor to Terminal to run a git command, and then forget what command I wanted to run. So I leave the git
that I've already typed, and change back to my editor.
I then remember what I wanted to run, switch back to terminal and type the command: git lg
. The problem is that I already typed git
once before, and I end up with one too many "git", which doesn't work:
$ git git lg
git: 'git' is not a git command. See 'git --help'.
But, adding one small alias to the config solves all your problems!
$ git config --global alias.git '!git'
$ git git lg
da54ad2 Update readme 2 hours ago
3543das Fix issue #32 4 days ago
...
This short line creates a "shell command alias" to have git run git, essentially making git
a valid git command (recursion FTW!)
So now our problem is solved, and craziness like this works!
$ git git git git git status
# On branch master
nothing to commit, working directory clean
Written by Magnus Dahlstrand
Related protips
2 Responses
I do this all the time, will have to give this a go :)
@petems Glad I was able to help someone :)