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?
To delete a remote branch, you can't use the git branch command. Instead, use the git push command with --delete flag, followed by the name of the branch you want to delete.
A: Git doesn't allow you to delete a local branch if you have the branch checked out. If you're having trouble deleting a Git branch, make sure you Git checkout a branch other than the one you want to delete.
You'll often need to delete a branch not only locally but also remotely. To do that, you use the following command: git push <remote_name> --delete <branch_name>. The branch still exists locally, though.
Delete branches We can delete a branch by calling the branch command and passing in the -d option, followed by the branch name.
The command to delete a remote branch is: Instead of using the git branch command that you use for local branches, you can delete a remote branche with the git push command. Then you specify the name of the remote, which in most cases is origin.
Assuming you want to delete the master, I resolved the problem in 3 steps: 1 Go to the GitLab page for your repository, and click on the “ Settings ” button. 2 In Default Branch, switch the default branch from your master to other one. 3 In Protected Branches, if there's any protection, unprotect the master. More ...
Repos often have a main branch for the main codebase and developers create other branches to work on different features. Once work is completed on a feature, it is often recommended to delete the branch. Git will not let you delete the branch you are currently on so you must make sure to checkout a branch that you are NOT deleting.
Local branches are branches on your local machine and do not affect any remote branches. The command to delete a local branch in Git is: git branch is the command to delete a branch locally.
Try
git push origin --delete feat
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