I am trying to delete a remote branch in git, I did:
git branch -r
...
origin/master
origin/dev
origin/branch_to_delete
now I try to delete origin/branch_to_delete
:
git branch -d origin/branch_to_delete
error: branch 'origin/branch_to_delete' not found
I did:
git fetch --all
and tried again, the same error. I tried with -D
but the same error.
but the branch is there, I can see it in github.com. What to do?
How to Delete a Branch Remotely. 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>.
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. You also need to specify the remote name ( origin in this case) after git push .
To completely remove a remote branch, you need to use the git push origin command with a -d flag, then specify the name of the remote branch. So the syntax representing the command for removing a remote branch looks like this: git push origin -d branch-name .
Delete a local branch You can't delete a branch if you're checked out that branch. You will see this error: Cannot delete branch 'branch-name' checked out at 'some-location'. To fix this, you will have to switch to a different branch. -d is shortcut for —-delete and it deletes a branch.
According to this post:
Deleting is also a pretty simple task (despite it feeling a bit kludgy):
git push origin :newfeature
That will delete the newfeature branch on the origin remote, but you’ll still need to delete the branch locally with git branch -d newfeature.
So the error you got just means you don't have a local copy of that branch, so you can ignore it. Then to delete the remote copy:
git push origin :branch_to_delete
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