14

I have cleaned my repo with BFG Repo Cleaner using the following procedure:

$ git clone --mirror git://example.com/some-big-repo.git
$ java -jar bfg.jar --strip-biggest-blobs 500 some-big-repo.git
$ cd some-big-repo.git
$ git reflog expire --expire=now --all
$ git gc --prune=now --aggressive
$ git push

I can see that my local repo has shrunk with 1GB. Great. The problem that I'm having now and that I haven't been able to find any info on is that now I would like to also shrink the size of the GitHub-repo as well. How to achieve this?

git push didn't work and I also tried git push origin --force --all which gave me this error message: error: --all and --mirror are incompatible

Roberto Tyley
  • 24,513
  • 11
  • 72
  • 101
PussInBoots
  • 11,028
  • 9
  • 52
  • 84

3 Answers3

11

My advice: don't worry too much about what GitHub reports as the repo size. For various reasons it won't accurately reflect the 'true' size of the repo.

What you really care about is the answer to this question:

How big is this repo on my disk if I do a fresh clone of it from GitHub?

The amount of data you have to download to do a fresh clone of your repo, and the amount of space it takes up on your disk, are the things you really care about (and nearly identical quantities). Try doing a fresh clone and seeing how much data gets transferred and how much room it takes up on your disk. It should match the size of your shrunken repo.

The number reported in the GitHub console (ie at https://github.com/settings/repositories, or in the GitHub API) is not really important to you, which is fortunate, because it enjoys a liberated and somewhat drunken relationship with the more important figure above, due to the use of Git Alternates, and git gc occurring only periodically on GitHub servers.

Side note: Bitbucket can also take time to update reported repo size.

Just because you ran git gc locally on your repo, doesn't mean GitHub have run it on their copy of your repo yet, and so their copy of your repo will appear much bigger for a while, even though when you clone it, only the 'essential' information is sent, and so you receive the smaller repo that you desire.

Full disclosure: I'm the author of the BFG Repo-Cleaner.

Roberto Tyley
  • 24,513
  • 11
  • 72
  • 101
  • RobertoTyley what about pushing? – LAFK 4Monica_banAI_modStrike Dec 29 '14 at 19:25
  • @little-ancient-forest-kami I'll need a little more context about your question (PussInBoots /was/ able to successfully push, tho his question might make it seem that he wasn't). If you post a new question I'll be happy to answer it if I can. – Roberto Tyley Dec 30 '14 at 09:30
  • Sorry maybe I misunderstood this answer but does this give a solution to updating the repository size on GitHub? – user5359531 Feb 22 '16 at 17:48
  • 1
    It seems, the same with [Bitbucket.org](http://www.bitbucket.org). After [...] push of 2.8GB files, we did a BFG cleanup, successfully completed `git push` and fresh clone now takes only 266MB. But Bitbucket still reports it as 2.8GB. – Arnis Juraga Apr 21 '16 at 20:37
  • @ArnisJuraga I'm also a bitbucket git repo user. My actual file size in total is 1GB but the repo size is almost 2GB. Overall total is 3GB. Then, I realize is that hidden .git folder and check the objects folder under .git folder and the size is over 2GB! I assumed this is where stored all commit infos. I was still thinking if it safer to use BFG to clean and remove old commit histories or still okay to delete the whole as is. – David Dimalanta Nov 09 '16 at 02:53
  • This really seems like a non-answer. If you can't push the mirrored clone, then there is no purpose to using the tool. – kim holder Sep 07 '17 at 21:10
  • 1
    Perfect answer! I shrunk a clone of my Github repo locally from 455 Mb to 54Mb and pushed it to Gihub. After pushing, the one on Github actually increased in size. I was very worried for a while that I had messed up my Github repo. I just needed to go to sleep and in the morning, Github had updated its copy and a new clone was done to 54Mb. – John Pankowicz May 06 '20 at 15:20
0

Push without the --all flag, that is, do

git push origin --force

and that should take care of it.

EDIT: Improvising upon discussion in comments

  • You can create a new repo on github,
  • push to it

    cd repo_directory
    git remote add new_origin url/to/new/repo
    git push new_origin --mirror
    
  • if things work out (no errors)
    • rename the github repos (the original to a dummy name and the new one to original)
  • Drop the remote new_origin. Since the github repo url should be same after you have renamed stuff, the original entry for [origin] in .git/config should hold good, and you only need remove the new remote added.

    git remote rm new_origin
    
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
  • Sorry forgot to mention that I already tried that command and that it gave me: Everything up-to-date. If I look at the repo size on github.com it still says the repo is over 1 GB. So this command doesn't work either unfortunatelly. – PussInBoots Aug 23 '14 at 06:39
  • @PussInBoots In that case, is creating a fresh repo on github and pushing to it, and renaming it later an option? – Anshul Goyal Aug 23 '14 at 06:42
  • @PussInBoots Also, can you update the question with the complete error message you get? – Anshul Goyal Aug 23 '14 at 06:44
  • Are you referring to the same thing VonC pointed out? Btw, that is the entire error message. – PussInBoots Aug 23 '14 at 06:51
  • @PussInBoots Yeah, I am referring to the same thing, though I would have first tried to create a new repo and push to it, and if things work out, than rename them (because what is the point of renaming if the pushes don't succeed later on) – Anshul Goyal Aug 23 '14 at 06:56
  • Not finnished testing mate. Will update this thread when I am satisfied. Thanks. – PussInBoots Aug 23 '14 at 21:03
0

If it is possible:

  • rename your current GitHub repo
  • create a new one with the same name
  • push again to your empty GitHub repo (git push --mirror)
  • check if the size warning persists in said new GitHub rpeo
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • By renaming my repo (which I btw don't want to mess with more than necessary) won't I mess things up? – PussInBoots Aug 23 '14 at 06:50
  • @PussInBoots no, the idea is to keep the original repo around, in case you don't like the new one. – VonC Aug 23 '14 at 06:51
  • @PussInBoots of course, you always can create a new empty repo, and push to that one new repo (without renaming the other one first), just to see if the size is better. – VonC Aug 23 '14 at 06:55