4

I am having an issue with a git remote branch that refuses to be deleted.

As per this answer, I have deleted my local branch with git branch -d qa without any issues, but when I run git push --delete origin qa to delete the remote branch I get the error:

! [remote rejected] qa (refusing to delete the current branch: refs/heads/qa)

I get the same error when running git push origin :qa, and when I try to force the deletion with git push --force origin :qa or the variation of git push origin --delete --force qa.

Does anyone know to to force the deletion of the remote branch?

If it is relevant, I am running git version 2.17.1

Thanks!

Update:

The issue was that qa was set as the default branch. In my repository I went to Settings > Branches > Default Branch and changed it to master, which allowed me to run git push --delete origin qa with no errors.

Jared Forth
  • 1,577
  • 6
  • 17
  • 32

2 Answers2

3

GitHub doesn't let you delete the default branch using Git.

You can either change the default branch to something else and then delete the qa branch, or you can delete the branch using the API.

bk2204
  • 64,793
  • 6
  • 84
  • 100
0

@bk2204 is correct that you are not allowed to delete the default branch on GitHub.

Instead, you need to go to the GitHub repository's Settings Page and select Branches tab on your left.

enter image description here

You then need to switch the default branch accordingly as illustrated on the above snapshot.

Thereafter you can run this command from Git

git push --delete

For example use git push origin --delete main to delete a branch named as main

You will get this confirmation.

enter image description here

Tonnie
  • 4,865
  • 3
  • 34
  • 50