Note that the correct solution to your problem could be simply using post-checkout
hook, as written in hacker's answer.
Below there is posible solution for your question.
You either use single git command in alias, like e.g.
[alias]
alias = config --get-regexp ^alias\\.
or you use any command with '!' prefix, perhaps using "sh -c
" trick; then you have to spell "git command", e.g.
[alias]
sed = !git ls-files --stage | grep ^100 | awk '{print $4}' | xargs sed
who = "!sh -c 'git log -1 --pretty=\"format:%an <%ae>\" --author=\"$1\"' -"
(not that alias.sed
is the best solution).
If you want for "git br <somebranch>
" to do "git checkout <somebranch>
", then "rap
", try
[alias]
br = !sh -c 'git checkout "$0" && rap'
Here &&
means: do next command if previous one is succesfull. You can use ;
instead to run command regardless of status of earlier command
BTW don't you switch branches using "git checkout <branch>
"? The "git branch <branchname>
" creates branch, without checking it out.