Switching the active branch in a bare git repository

If you ever need to delete the “active” branch in a git repository, you need to first switch the active branch. Because you cannot delete the branch you are sitting on… You cannot checkout a branch, as you would usually do. You have to change the symbolic reference called HEAD. You can do this with the symbolic-ref command:

$ git branch
* deletethis
$ git symbolic-ref HEAD refs/heads/somebranch
$ git branch
* somebranch
$ git branch -d deletethis

Leave a Reply

Your email address will not be published.