Shell script to check if specified Git branch exists? [duplicate]

NOTE: This always returns true. This is not the right answer to the question, even though it has been accepted….

You could always use word boundaries around the name like \< and \>, but instead let Git do the work for you:

if [ `git branch --list $branch_name` ]
then
   echo "Branch name $branch_name already exists."
fi

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)