Thursday, 12 March 2015

Reduce your git repository size in minutes

It is a fact that your git repository accumulates a lot of history. Even though git was not built for binary files, people do store them in repositories and that contributes to the growth. At a certain point you might be removing binary files and looking back at the history of an image is not something that you do every day. So why not remove all the massive blobs from history? I know, it sounds like you need to rewrite the history and that is dangerous isn't it? Not quite, with a nice tool called bfg.

Right, let's start:

1. Download bfg or install it via brew, yum, etc.

2. Create a bare clone of your git repository:
git clone --mirror git://something.com/big-repo.git

3. Create a backup of the repository(just in case)
cp -r big-repo.git big-repo.git_bak

4. Run this:
bfg -b 100K big-repo.git

This will remove all files over 100K, but don't worry, HEAD is protected. There are many other options(including protecting other branches), have a look at their documentation or just run bfg with no arguments to see the options.

5.  Run git gc to actually remove the files

cd big-repo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive

6. [Optional] Create a new repo where you push the changes. I like to push the changes into a new repo to be 100% sure that the repository is in a good state. Before pushing, change the url for remote "origin" inside big-repo.git/config.

7. Push the changes:
git push

8. Done. Enjoy your lean repository!

12 comments:

  1. Fuck this guy. ^^ Spammer. Don't click.

    ReplyDelete
  2. Fastest Cars In The World We can measure automotive excellence in several ways, but top speed which a automobile can achieve is the one everyone secretly cares about the most

    ReplyDelete
  3. "This photo is perfect except for background which is...". Well, let's say "bad". Have you ever thought like that? Probably, you even made an attempt or two to edit the picture with the ruined Photo Background Editor, to no avail. Surely, not all of us are designers or at least IT savvy. So, here is a way for the rest of humanity to change the back scene of any photograph – the Photo Scissors online tool.

    ReplyDelete
  4. Nearbest10 is a participant in the Amazon Services LLC Associates Program which is an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com. Amazon, the Amazon logo, AmazonSupply, and the AmazonSupply logo are trademarks of Amazon.com, Inc. or its affiliate.

    ReplyDelete
  5. Packers and Movers Chennai Give Safe and Reliable ***Household Shifting Services in Chennai with Reasonable ###Packers and Movers Price Quotation. We Provide Household Shifting, Office Relocation, ✔✔✔Local and Domestic Transportation Services, Affordable and Reliable Shifting Service Charges @
    Packers And Movers Chennai

    ReplyDelete
  6. Gypsum designer providing innovative building solutions to meet the demands of customers for sustainable performance solutions. Gypsum designer Inc. is a key resource for architects, contractors, and design professionals.

    ReplyDelete

  7. الرائد من افضل شركات الخدمات المنزلية في المملكة وخدماتها تغطى كل المنطقة العربية للمزيد قم بزيارة
    شركة تنظيف خزانات بمكة شركة تنظيف خزانات بمكة
    افضل شركة تنظيف منازل بالمدينة المنورة افضل شركة تنظيف منازل بالمدينة المنورة
    افضل شركة تنظيف بمكة بالبخار افضل شركة تنظيف بمكة بالبخار
    شركة نقل عفش من جدة الى الاردن شركة نقل عفش من جدة الى الاردن
    شركة تنظيف مجالس بمكة شركة تنظيف مجالس بمكة

    ReplyDelete
  8. Packers and Movers Bangalore as a Services providing company can make all the difference to your ###Home Relocation experience. Bangalore based Company which offers versatile solutions, Right team that easily reduce the stress associated with a ✔✔✔Household Shifting, ***Vehicle Transportation. we help things run smoothly and reduce breakages and offer you seamless, Affordable, Reliable Shifting Services, Compare Shifting Charges @
    Packers And Movers Bangalore

    ReplyDelete