Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git delete remote branch not working: branch not found

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?

like image 566
doniyor Avatar asked Jul 14 '15 10:07

doniyor


People also ask

How do I delete a remote branch that is not local?

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

How do I force delete a remote branch?

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 .

How do I remove a remote git branch?

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 .

Why can't I delete a branch?

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.


1 Answers

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
like image 58
cvesters Avatar answered Sep 24 '22 23:09

cvesters