gitgitlab

Why can't I delete a branch in a remote GitLab repository?


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?


Solution

  • 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.

    Details

    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: