4

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

2 Answers2

7

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'"
2

The ; semicolon starts a comment that terminates your Git alias early hereby making it incomplete at the time Git tries to run the external shell command you aliased.

The manual page of the git-config command states that a ; semicolon starts a comment that extends until the end of a line because Git configuration files are written in the INI format.

Tim Friske
  • 2,260