2

I accidentally created a branch called "remotes/origin/remotes/origin/aclark" and can't delete it with:

git branch -d remotes/origin/remotes/origin/aclark

Git says:

error: branch 'remotes/origin/remotes/origin/aclark' not found.

I tried some of the suggestions here: Deleting a badly named git branch, but they are geared more towards bad branch names that start with "--".

Is there any way an end user can delete this branch or do I need a git admin? (The branch in question lives at gitorious).

Thanks

Alex

Community
  • 1
  • 1
aclark
  • 4,345
  • 1
  • 19
  • 31

1 Answers1

11

This is a remote branch, so you need to delete it on the server. To do that, you need to push an empty reference.

$ git push origin :remotes/origin/aclark

Note, the syntax of the git push command is:

$ git push <remote> <local-reference>:<remote-branch-name>

So in the case, we are pushing an empty reference, and the remote name is the name of the branch we want to destroy. In your case, the branch name "remotes/origin/remotes/origin/aclark" indicates that it is a remote branch on the remote server name "origin", and the name on the distant server is "remotes/origin/aclark".

The other client will need to issue the following commands to have the branch removed from their local repository (if they fetched when the invalid branch existed):

$ git fetch origin
$ git remote prune origin

More information can be found in the git-push and git-remote manpages.

Sylvain Defresne
  • 42,429
  • 12
  • 75
  • 85
  • Thanks! This has just begun to sink in. And indeed, git push origin :remotes/origin/aclark did the trick. Thanks again! – aclark Jan 07 '11 at 19:31