Every now and then I wind up typing "git
" then think of something else, then type e.g., "git checkout master
". Of course, this leaves me with
$ git git checkout master
git: 'git' is not a git command. See 'git --help'.
Did you mean this?
init
$
Is there a way to create a git alias named git
that is a no-op? I've tried the obvious like "git = ''
" and "git = ""
" and "git = " "
" but not surprisingly, they all result in responses like Expansion of alias 'git' failed; '' is not a git command
.
Your git aliases are often stored per your user's configuration at ~/. gitconfig . You can also manually set aliases using, for example, the command git config alias. s 'status -s' .
Git aliases are a powerful workflow tool that create shortcuts to frequently used Git commands. Using Git aliases will make you a faster and more efficient developer. Aliases can be used to wrap a sequence of Git commands into new faux Git command.
The simplest way to add a git alias is by running a command to add the alias to the git global configuration file. For example, running the command git config --global alias. hist "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short" will add the alias git hist .
I figured out the answer: Rather than alias, you just need to have script named git-git
in your path with the contents:
#!/bin/bash
git "$@"
so when you say "git git
", git looks for git-git
, and passes the remaining arguments to it. Of course, by recursion, you can be very absent minded and say "git
" as many times as you like:
$ git git git git git git git git git git git git status # <- still works
Update:
Yesterday I hit enter on gitgit status
. So, while you are at it, may as well symlink git-git
to gitgit
. That doesn't chain indefinitely, but still.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With