Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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.

share|improve this answer
    
Talk about RTFM; I though it was something native to bash. Thanks! :) –  scribu Sep 5 '12 at 22:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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