I'm trying to delete a branch both locally and in a remote GitLab repository. Its name is origin/feat
. I tried git push --delete origin feat
. Git complains:
remote: error: By default, deleting the current branch is denied, because the next
remote: 'git clone' won't result in any file checked out, causing confusion.
remote:
remote: You can set 'receive.denyDeleteCurrent' configuration variable to
remote: 'warn' or 'ignore' in the remote repository to allow deleting the
remote: current branch, with or without a warning message.
remote:
remote: To squelch this message, you can set it to 'refuse'.
remote: error: refusing to delete the current branch: refs/heads/feat
OK makes sense, so I tried switching to origin/master
with git checkout master
and it tells me: Already on 'master'
. Does the current branch also need to be set in the remote directory? How would I do that?
Edit (per comments by OP—I have not used GitLab): GitLab has a web interface with dropdowns. You need the one under the Settings view (not the Project view). Choose a branch in the Settings view under "Default branch" and click "Save changes" to set the current branch on the server.
You have the right idea, but you have to remember that there are two repositories—two Gits—involved.
Any time you get text prefixed with remote:
, this means the text is coming from the other Git. So when you have your Git ask the other Git to delete feat
, it's the other Git complaining that feat
is the current branch.
Hence:
Does the current branch also need to be set in the remote directory?
Yes (well, "instead of" rather than "also").
How would I do that?
In general, the same way you do it with any repository: log in, cd
to the repository directory, and run git checkout
. But there's a hitch or two with push-able repositories on servers:
It's probably a --bare
repository, so that you can't use git checkout
directly. The trick here is to use git symbolic-ref
to update HEAD
:
git symbolic-ref HEAD refs/heads/master
Of course, this assumes you can log in (see first point). If there is, say, a web interface that lets you change the current branch on the remote, it is going to have to do this git symbolic-ref
operation for you.