How to embed bash script directly inside a git alias

Seba Illingworth picture Seba Illingworth · Aug 21, 2009 · Viewed 30.7k times · Source

Can I embed the following bash shell code:

for name in $(git diff --name-only $1); do git difftool $1 $name & done

directly into the creation of a git alias:

git config --global alias.diffall ***my-bash-code-here***

This leads on from my previous question/answer on SO, where I put the code into a .sh file and then aliased to the file:

git config --global alias.diffall '!sh diffall.sh'

But in the never-ending quest for simplicity, there's gotta be a way to skip the file and insert code directly into the alias? I can't figure out the format...

Answer

u0b34a0f6ae picture u0b34a0f6ae · Aug 21, 2009
git config --global alias.diffall '!sh diffall.sh'

This is redundant in one way. If you are going to add 'diffall.sh' into your $PATH anyway, why not save it as 'git-diffall', and save yourself from declaring an alias. Yes, "git diffall" will run it.