I have a Git command alias to checkout the latest tag from a repository:
~/.gitconfig
:
checkout-latest = !git checkout $(git describe --tags `git rev-list --tags --max-count=1`)
So I can use it in properly tagged repositories like this:
$ git checkout-latest
I have command aliases for the checkout command:
~/.gitconfig
:
co = checkout
The checkout-latest
does not work with the command aliases for checkout:
$ git co-latest
git: 'co-latest' is not a git command. See 'git --help'.
How can I configure Git so that I can use latest as a tag alias that points to the programmatically determined latest tag? I would like to use it like this:
$ git checkout latest
and
$ git co latest
Note that there is no dash between the subcommand and the tag in my desired variants.
The only solution to this sort of thing I can think of is a
git
shell function that does "dispatch" based on arguments.Something like this:
The tag aliases need to be invalid as normal refs to be safe for hence the use of
check-ref-format
.This construct allows for arbitrary tag "aliases" to be added via the case statement.
This function is very limited in terms of what arguments can be used if you want to use the tag "alias". Specifically you cannot pass any. The command must be
git checkout <alias>
. Parsing all validgit checkout
combinations is simply too hard to bother with for this now (though it could probably be done).