If you place an executable named
git-MYCOMMAND anywhere in your $PATH, then running `
git MYCOMMAND` will call that script, just as if it were an official command underneath git. It can be anything from a shell script to a compiled C executable, it's totally up to you.
This is a good explanation of the details of this:
git MYCOMMAND --help` won't actually pass the
--helpparameter on to the executable, rather git will look for a man page called
git-MYCOMMAND.1in the manpath, and error out if one can't be found.
Git aliases are nice, but they're nowhere near as powerful and flexible as custom git commands can be.
It seems like git has an endless number of commands. Most of them are user-oriented, but there are a few that are particularly useful for ingestion into your custom scripts:
--git-dirfor displaying the abs/relative path of the
--show-toplevelfor displaying the top-level directory of the working tree (
--show-cdupfor the relative path)
--is-inside-git-diror within a work-tree using
--branches), tags (
--tags) and the refs can also be filtered based on the remote (using
git rev-parse HEAD^`
git log --format=%B -n 1 <revision>
git rev-parse --abbrev-ref HEAD
There are some Perl modules for accessing some of the Git plumbing:
While we're here, this is a list of custom commands that other people have published, that I particularly like: