On Mon, 26 Nov 2012 07:06:35 -0800 (PST)
Jeffrey Marans <jmar...@gmail.com> wrote:

> I've done a cvs2git conversion of a number of cvs modules and was
> unable to exclude the private working branches, PWB*.
> I'd like to delete them from the git repos and have tried the
> following, but the branches live on regardless of the output messages.
> By that I mean if I clone another instance of test, the branches
> still show up on the origin server.
> mkdir test
> cd test
> git clone git@git:/git/gitroot/oacis/test
> cd test
> git branch -r | grep PWB
>   origin/PWB9
> for i in `git branch -r | grep PWB`;do git branch -rD $i;done
> Deleted remote branch origin/PWB9 (was a8ab921).

You misunderstand what those "origin/foo" branches are.
Unfortunately, the naming of these things adopted by Git just adds to
the confusion (though I don't think they could do it any better).

Those branches *in your local repository* (which are not shown by a call
to `git branch` without the "-r" command-line option) are the
so-called "remote branches".  They capture the state of the branches
the corresponding remote repository had the last time you did
`git fetch` from that repo.  They exist only in your repo, as a
reference, and deleting them (or renaming or whatnot) does not affect
any remote repository in any way.  They are like bookmarks.  They
exists to provide convenient handles to "remote" history, but in the
same way as removing a bookmark from a book does not affect a book,
removing a remote branch from your local repository does not even hits
the network and modifies only your local repository.  The next
`git fetch origin` will (re-)create these branches.

To delete something from a remote repo you have to use a somewhat
obscure (on the first sight) feature of the `git push` command -- you
should push *nothing* to a named remote object (a branch in your case).

The idea goes like this: the full syntax to update a branch named
"master" in the remote repo with the contents of your local branch
named "master" is spelled as
$ git push origin master:master
Git allows you to drop the remote object specification -- the ":master"
part -- in which case it's assumed the remote object will have the same
name and type, so when you do
$ git push origin master
Git takes your local object "master" (be it a branch or a tag -- it
does not matter) and tries to update a same-named object in the remote
repo, creating it if necessary.

If you want to delete an object from a remote repo, you push nothing to
it -- using the full syntax:
$ git push origin :master
means updating an object named "master" in the remote repo with
nothing, thus deleting it.

So to delete a branch named "PWB9" from "origin" you should do
$ git push origin :PWB9

You could also employ the fact Git is able to use wildcards for both
local and remote objects, so you could possibly do
$ git push origin ':refs/heads/PWB*'
where you tell it to remote all heads (branches) matching the "PWB*"
pattern.  Be sure to protect the pattern from the shell, if needed.

As usually, this syntax is explained in the `git push` manual page.
And in The Book [1] as well.

1. http://git-scm.com/book/en/Git-Branching-Remote-Branches


Reply via email to