10

I have a bare public repo.

The problem is that I'm already using it for a long time and that means that there is a lot of junk in the bare repo. There are tons of dead branches, removed tags, etc...

Is there some command to cleanup the bare repo? Some like git remote prune that works for the opposite scenario?

Edit: Since there seems to be some confusion. This is my setup:

DevelMachine1
   ^
   |
   v
MainDevelRepo <-> MainRepo -> PublicBareRepo (with a lot of junk) -> The World
   ^
   |
   v
DevelMachine2
Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151

2 Answers2

4

All those non-referenced objects should be gone eventually, considering:

So even if you don't have a direct local access to the remote bare repo, the simple fact to "use" it (push to it) is enough to trigger gc and prune on said bare repo.


Note: my answer was in the context of a remote bare repo (you don't directly work with a bare repo, you are pushing to it)

git remote prune is an operation done on a local repo (a non-bare one, where you fetch some remote branches and have a lot of tracking branches under the remotes/* namespace of said local repo)

Cleaning a remote (bare here) repo means pushing :refs as mentioned by Magnus Skog in his answer.
If those refs don't exist on the current local repo 'DevelMachinex' , then there is no real other solution than:

  • cloning --mirror the remote bare repo 'MainDevelRepo' (you will get all those stale branches as local remote tracking branches)
  • delete branches locally
  • push --mirror, since the documentation does mention "deleted refs will be removed from the remote end".
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I think what the OP means is that the remote has stale branches, as well as some tags he doesn't want anymore, so he wants to do some kind of push-delete operation to delete the refs on the remote that aren't in his local repo. (Like `push --mirror`, except only on heads and tags... and unfortunately you can't do something like `git push --delete --all; git push --all`.) – Cascabel May 15 '11 at 15:01
  • Please read up on what `git remotes prune` actually does. What you are describing is totally irrelevant to this question. – Šimon Tóth May 15 '11 at 15:04
  • 1
    @Let_Me_Be - you mean `git remote prune` . I think you should use it properly before asking someone to read up on it. – manojlds May 15 '11 at 15:14
  • @Let_Me_Be: just edited my answer to address your specific scenario – VonC May 15 '11 at 15:44
4

After even some more info:

MainRepo -> PublicBareRepo (with a lot of junk) -> The World

So the problem is here. Once in a while you do a push from MainRepo to PublicBareRepo, which now contains stuff that are no longer valid and shouldn't be there. In the future, make sure that you only push up branches that should be there. I guess the main thing now is to remove branches from it, and then I have to step back to my original answer (assuming we are talking about the same kind of junk)

git push PublicBareRepo :someBranch1
git push PublicBareRepo :someBranch2

After some more information from the OP:

It seems it's the repo design thats causing problems and a --mirror is the way to solve this. If A is the main bare repo that devs are pushing their stuff to, and if B is a public bare repo, then B should be a clone of A with the --mirror option.

What needs to be done is to do "git remote update" (assuming B already is a mirror of A) on B so it will update itself to again be identical to A.


Original answer:

If you want to remove a branch on the remote repository you can do:

git push origin :branchName

The same goes for any ref really, e.g. for a tag:

git push origin :tagName
rtn
  • 127,556
  • 20
  • 111
  • 121
  • What if there are two dozen old branches? It does seem like there should be some single command for this... `--mirror` is perhaps the closest, but it does too much. – Cascabel May 15 '11 at 15:10
  • The problem is that those branches don't exist locally. Plus simply editing the bare repo would be much easier then calling git push for each of the stale branches. What I'm looking for is something like `git remotes prune` that would automatize the task. – Šimon Tóth May 15 '11 at 15:12
  • Do we push tags? As in isn't there `--tags` ? And once tags are removed, why do we even care about cleanup? – manojlds May 15 '11 at 15:13
  • Then you have to issue two dozen commands. --mirror only says you want to clone an exact copy of the bare repo. – rtn May 15 '11 at 15:15
  • @let_me_be: Hmm, when you say locally, they doesn't exist locally on the remote? – rtn May 15 '11 at 15:19
  • If you want to remove branches on a upstream repository, this is the way to do it and a minus vote is not justified. But I might have gotten the question wrong. Let me know and I'll remove my answer. Thanks. – rtn May 15 '11 at 15:24
  • @Magnus My configuration is DevelRepos <-> MainRepo -> PublicBareRepo (with lot of junk) -> BuildMachines+OtherPeople Now I want to make BareRepo to be the same state as the MainRepo (including the removal of old stuff - branches, tags, etc...) – Šimon Tóth May 15 '11 at 15:39
  • Aha, so MainRepo and PublicBareRepo are both bare. Then one of them should indeed be a mirror of the other. This would solve a great deal. You do your modifications in one repo and then just update the mirror. – rtn May 15 '11 at 15:43
  • Please see my revised answer. Thanks. – rtn May 15 '11 at 15:47
  • @Magnus No, MainRepo is a normal repo, the reason why I have this separate repo is that DevelopRepository can contain a lot of junk from time to time. MainRepo simply contains a clean version of the repository. – Šimon Tóth May 15 '11 at 15:47
  • Hehehe ok. Back to the drawing board :) – rtn May 15 '11 at 15:52