I have a single branch on this GitHub repository (which is not master) and now I'm trying to rename it and for some reason I am getting this error:
git push origin :OldName
To [email protected]:user/gitRepo.git
! [remote rejected] OldName (refusing to delete the current branch: refs/heads/OldName)
error: failed to push some refs to '[email protected]:user/gitRepo.git'
Is this because I don't have any master branch? Here's my git branch -a
:
OldName
remotes/origin/HEAD -> origin/OldName
remotes/origin/OldName
This is not a [git] restriction, but [github] doing an extra layer of sanity protection for you. Change the [default branch] in the GitHub project of yours, and then try again.
Sample URL (change [user] and [project]):
https://github.com/[user]/[project]/settings/branches
If the output from git branch -a
be accurate, then it appears you only have a single branch OldName
, and single corresponding branch by the same name on GitHub. It doesn't make much sense for you to be deleting the only branch in the repository, because then there would be no content, nothing, in that repository (except for maybe the reflog, if that still exists).
Specifically, the error is likely being caused for a slightly different reason. Since the OldName
branch is the only branch in GitHub, is also most likely the default branch for your repository. GitHub will not allow you to delete the default branch, because then it means that someone browsing your repo might not be able to see content.
To get around this problem, you can create a branch with the name you want, and do the deletions from there:
Locally
git checkout -b NewName # create a dummy branch from OldName
git push origin NewName
On GitHub
Change the default branch to NewName
Locally (again):
git push origin :OldName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With