Git Alias - Multiple Commands and Parameters

Stella picture Stella · Sep 23, 2011 · Viewed 69.1k times · Source

I am trying to create an alias that uses both multiple Git commands and positional parameters. There are Stackoverflow pages for each, and it would appear painfully obvious to do both, but I am having trouble.

As an example, I want to switch to branch foo and perform a status. So in my .gitconfig, I have:

  [alias] 
     chs = !sh -c 'git checkout $0 && git status'

which doesn't work. Whereas something like this will work.

chs = !sh -c 'git checkout $0'

echoes = !sh -c 'echo hi && echo bye'

Any insight would be appreciated.

Answer

Olivier Verdier picture Olivier Verdier · Sep 23, 2011

This will work (tested with zsh and bash):

[alias] chs = !git checkout $1 && git status