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 --help
parameter on to the executable, rather git will look for a man page called git-MYCOMMAND.1
in 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-dir
for displaying the abs/relative path of the .git/
directory--show-toplevel
for displaying the top-level directory of the working tree (--show-cdup
for the relative path)--is-inside-git-dir
or within a work-tree using --is-inside-work-tree
--is-bare-repository
--branches
), tags (--tags
) and the refs can also be filtered based on the remote (using --remote
)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: