I'm using bash version 4.1.2(1)-release (x86_64-redhat-linux-gnu) on cygwin with git 1.7.1. I wanted to make an alias for a command that needed to use the input argument twice. Following these instructions, I wrote

branch-excise = !sh -c 'git branch -D $1; git push origin --delete $1' --

and I get this error:

$> git branch-excise my-branch
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file

I've tried both a - and a -- at the end, but I get the same errors. How can I fix this?

  • What is sh on your system? Why are using sh and not bash here? – Arkadiusz Drabczyk Oct 29 '15 at 14:04
  • 1
    @ArkadiuszDrabczyk I was following directions from the git manual page that I linked to. Also this stackexchange comment stackoverflow.com/questions/3321492/… claims that sh is more universal across *nixes. – user394 Oct 29 '15 at 14:19
  • @ArkadiuszDrabczyk why in the world would you use bash and not sh there? There's no bashism there, why use a slower, heavier and less portable shell when there's no reason to? – terdon Oct 29 '15 at 14:21
  • @terdon: I wouldn't but OP says that he uses and tried bash and shows example where sh is used – Arkadiusz Drabczyk Oct 29 '15 at 14:23
  • @ArkadiuszDrabczyk ah, fair enough. Many people mistakenly assume that bash == sh, I'm guessing that's what happened here. – terdon Oct 29 '15 at 14:24

man git-config says:

The syntax is fairly flexible and permissive; whitespaces are mostly ignored. The # and ; characters begin comments to the end of line, blank lines are ignored.


branch-excise = !bash -c 'git branch -D $1; git push origin --delete $1'

is an equivalent to:

#!/usr/bin/env bash

bash -c 'git branch -D $1

Running the above script prints:

/tmp/quote.sh: line 3: unexpected EOF while looking for matching `''
/tmp/quote.sh: line 4: syntax error: unexpected end of file

One solution is to put a whole command in ":

branch-excise = !"bash -c 'git branch -D $1; git push origin --delete $1'"

However, it still doesn't work because $1 is empty:

$ git branch-excise master
fatal: branch name required
fatal: --delete doesn't make sense without any refs

In order to make it work you need to create a dummy function in .gitconfig and call it like this:

branch-excise = ! "ddd () { git branch -D $1; git push origin --delete $1; }; ddd"


$ git branch-excise  master
error: Cannot delete the branch 'master' which you are currently on.
  • 2
    Worth knowing: unlike a shell, if you accidentally omit the trailing semicolon inside of the ddd definition, you also get the same confusing "syntax error: unexpected end of file" error. – ecmanaut Sep 25 '17 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.