I need to create a Git branch using shell script, but since the branch may exist, I need to be aware of that. Currently I'm using:
if [ `git branch | grep $branch_name` ]
then
echo "Branch named $branch_name already exists"
else
echo "Branch named $branch_name does not exist"
fi
But the problem is the grep
command finds branch name without matching the exact name, that is, if I grep name
then branch with a name branch-name
would be matched.
So is there a better way to do this?
Thanks!