I have created branch with "git checkout -b mybranch". It seems that something went wrong, and now I can't delete it using "git branch -D mybranch". It says: error: branch 'mybranch' not found.
Deleting a branch LOCALLY Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet.
The command to delete a local git branch can take one of two forms: git branch –delete old-branch. git branch -d old-branch.
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.
If git branch -D
really isn't working, then your only option is to side-step it and edit the git check-out's state yourself. You should go to the root-directory of your check-out (where the .git
directory is) and
.git/packed-refs
; if you see a line with your branch name then delete it.git/refs/heads
for a file named after your branch; if you see one, delete itI used git update-ref -d refs/heads/<branch name>
to fix this issue. Presumably, this does the same thing as what Rup suggests in the selected answer except it's interfaced via Git's CLI.
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