Usually, git aliases are confined to a single command:

git config --global alias.ci commit

So, instead of git commit you could do git ci

But it seems you can insert a function in there as well:

git config --global alias.up-sub '!f() { cd $1 && git checkout master && git pull && git submodule update --init --recursive; }; f'

This allows you to call git up-sub some-submodule

The question is: how does it work? I haven't seen the !f() syntax in any other context.


Looks like a regular shell function definition and invocation. Only the bang stands out, but a quick search through the git-config(1) manual shows an explanation:

If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command. For example, defining "alias.new = !gitk --all --not ORIG_HEAD", the invocation "git new" is equivalent to running the shell command "gitk --all --not ORIG_HEAD". Note that shell commands will be executed from the top-level directory of a repository, which may not necessarily be the current directory.

Without the bang, it would alias a git subcommand.

  • Talk about RTFM; I though it was something native to bash. Thanks! :) – scribu Sep 5 '12 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.