Git – Create Aliases with Multiple Commands Using ; and &&

gitquotingshell

I want to have an alias that execute a command and then whether it fails or no it execute other commands that depends on the success of each other.

So I have something like that in .gitconfig

getpull = !sh -c 'git remote add $0 $1; git fetch $0 && git checkout -b $2 $0/$2'

With that command I get the following error (I donno as when I copy this to the shell it works fine):

sh -c 'git remote add $0 $1: 1: sh -c 'git remote add $0 $1: Syntax     error: Unterminated quoted string

Best Answer

I figured it out, it seems something with .gitconfig parser and to solve it we just need to wrap the whole command with double quotes as follow

"!sh -c 'git remote add $0 $1; git fetch $0 && git checkout -b $2 $0/$2'"
Related Question