Git aliases can be removed with git config --global --unset alias.<badalias>
.
I want to make life easier and be able to delete git aliases with:
git rmalias <badalias>
.
My attempt for this alias is:
git config --global alias.rmalias '!git config --global --unset alias.'
The problem I'm running into here is
error: key does not contain variable name: alias.
since the command now reads
git config --global --unset alias. badalias
.
How can the alias be defined such that it puts the extra parameter on the right place?
The trick to more complex aliases, including ones that concatenate parameters to other text, is to create and immediately run a shell function in the alias command:
This creates a function
f
which uses the first parameter$1
in the Git command it runs. Then it runs the functionf
(which passes all the parameters given to the alias on the command line as parameters to the function).Creating these kind of aliases on the command line requires extreme care with the spacing and quoting, so copying and pasting is a smart idea -- if you use double quotes around the whole alias your shell may do history expansion on
!
and break the alias, and you leave out the spaces around the punctuation in the function definition, that can make the function definition invalid.