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
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
All those non-referenced objects should be gone eventually, considering:
git prune
is called by git gc
git gc
is called automatically when you are pushing to a bare repo
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:
MainDevelRepo
' (you will get all those stale branches as local remote tracking branches)push --mirror
, since the documentation does mention "deleted refs will be removed from the remote end".If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With