Search code examples
gitgerritrepo

how to create aliases for full git commands


I created a git alias as follows but when I run git gbf4364 it throws an error, what am I missing?

git config --global alias.gbf4364 'git clone ssh://username@gerrit.sd.company.com:29418/projectname'

Solution

  • Git aliases are assumed to be git commands unless stated otherwise. Git simply replaces the new command with whatever you alias it for. However, maybe you want to run an external command, rather than a Git subcommand. In that case, you start the command with a ! character1.

    As clone is a git subcommand, use git config --global alias.gbf4364 'clone ssh://username@gerrit.sd.company.com:29418/projectname', which will translate to git clone [...]

    You shouldn't add git in the alias. Otherwise git gbft4364 equals to git git clone ssh://username@gerrit.sd.company.com:29418/projectname, it will have two git.

    When you want to delete the alias, use git config --global --unset alias.gbft4364