I'm using zsh and I added "gc" as an alias for "git checkout" as below in the .zshrc file.
alias gc="git checkout "
When I execute git checkout dev
, it works fine. But gc dev
doesn't work as expected. It shows:
error: pathspec 'dev' did not match any file(s) known to git
May I have your advice on this issue? Thanks.
Note that I'm aware of Git Alias settings like git config --global alias.co checkout
, but it still needs to type git co
, which is 5 characters plus a whitespace. I'm wondering if it can be aliased as gc
.
CodePudding user response:
You can achieve that with a function
gc() {
git checkout "$1"
}
CodePudding user response:
Many thanks to @phd and @Gairfowl for investigating into this. They are absolutely right--my alias definition is overridden by the aliases of the git plugin of ohmyzsh, who has already done what I'm exactly trying to do. The full list of omz git aliases can be found here.
The lesson I learned is that when an alias is not working as expected, firstly check if there are other aliases sharing the same name. In ZShell, compgen -a
(or alias
with omz) will list all aliases.