views:

3193

answers:

3

In my current repo I have the following output:

$ git branch -a
* master
  remotes/origin/master
  remotes/public/master

I want to delete 'remotes/public/master' from the branch list:

$ git branch -d remotes/public/master
error: branch 'remotes/public/master' not found.

Also, the output of 'git remote' is strange, since it does not list 'public':

$ git remote show 
origin

How can I delete 'remotes/public/master' from the branch list?

Update, tried the 'git push' command:

$ git push public :master
fatal: 'public' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

Solution: The accepted answer had the solution at the bottom!

git gc --prune=now
+17  A: 

You might be needing a cleanup

git gc --prune=now

or you might be needing a prune

git remote prune public

   prune
       Deletes all stale tracking branches under <name>. These stale branches have already been removed from
       the remote repository referenced by <name>, but are still locally available in "remotes/<name>".

       With --dry-run option, report what branches will be pruned, but do no actually prune them.

However, it appears these should have been cleaned up earlier with

git remote rm public 

   rm
       Remove the remote named <name>. All remote tracking branches and configuration settings for the remote
       are removed.

So it might be you hand-edited your config file and this did not occur, or you have privelage problems.

Maybe run that again and see what happens.

Kent Fredric
$ git push public :master<br>fatal: 'public' does not appear to be a git repository<br>fatal: The remote end hung up unexpectedly<br>
Casey
I don't want to delete the branch on the remote side. I think there is a subtle difference.
Casey
er, the question is effectively asking "how do I delete a remote branch". Thats what those paths are.
Kent Fredric
I will rephrase the subject if that makes it more clear what I'm asking, but the command show exactly what my problem is.
Casey
+8  A: 
git push public :master

This would delete the remote branch named master as Kent Fredric has pointed out.

To list remote-tracking branches:

git branch -r

To delete a remote-tracking branch:

git branch -rd public/master
Alan Haggai Alavi
+6  A: 

git gc --prune=now is not what you want.

git remote prune public

or git remote prune origin # if thats the the remote source

is what you want

tongueroo
Why, what is the difference?
Casey
@Casey$ git gc # does like a defragment for the git files to speed up the respository$ git remote prune origin # will clean up the delete the stale remote branches that show up with "git branch -r | grep origin". Thats what the question is asking I believe. So, the commands are totally different.
tongueroo