According to my flow I am pushing the new changes to my server new_release branch and then a script on the server takes care of applying the new release. At the moment when script is executed on the server git repo has two branches – master and new_release. At a given point the script executes the following:
#reset changes on the master branch
echo "Resetting master changes..."
git reset --hard HEAD
if [ $? -ne 0 ]; then
echo "Error: Cannot reset master changes"
exit 1
fi
#remove untracked files
echo "Removing untracked new files..."
git clean -fd
if [ $? -ne 0 ]; then
echo "Error: Cannot clean the repository"
exit 1
fi
#merge changes from new_release into master
echo "Merging master with the new_release..."
git merge new_release --ff-only
if [ $? -ne 0 ]; then
echo "Error: Cannot merge changes from new_release into master"
exit 1
fi
#remove new release branch
echo "Deleting the new_release branch..."
git branch –d new_release
if [ $? -ne 0 ]; then
echo "Error: Cannot remove the new_release branch"
exit 1
fi
However, once I execute the script I see that “git branch -d new_release” instead of deleting the local branch leaves it there and in turn created a new branch with name “d” !!
Furthermore, I see the following output regarding that new “d” branch:
$ git branch
* master
new_release
d
$ git branch -d d
error: remote branch 'd' not found.
$ git show-branch d
fatal: bad sha1 reference d
What am I doing wrong in my script? And also can someone help me recover from that error and get rid of that “d” branch? It’s on my production server.
First, +1 for showing exactly what you did, because I wouldn’t have figured it out if you’d described what you wanted it to do without showing the actual script. Good question writing.
Did you copy’n’paste bits of that script from the web?
This doesn’t do what you think it does:
That is not
-dit’s–dwhich is a different character (it’s a three-byte UTF8 character, not an ASCII 45.) So you’ve created a new branch called–dand the funny dash character isn’t showing up on your terminal, probably because you’re not using a UTF-8 locale in your terminal settings, so it just shows up asd. The reason you can’t get rid of it again withgit branch -d dis that it’s really called–dnotd.So to fix the script, change the script to
-dand it should delete branches.To delete the unwanted branch try:
The first command deletes it locally, the second deletes it remotely. This is assuming the branch name is “–d” and not something else that has stripped out that first character, but I think it should work.