2

I have a fork in Github of a repo that has large binary files in the vendor folder. I want to remove that folder, so that the repo returns to a normal size.

Problems/Challenges:

  • There are 7 – non sequential – commits concerning the vendor folder.
  • There are hundreds of commits separating those commits. Since they are OSS contributions, it would not be appropriate to lose that history.
  • It is OK if people who has forked my repo cannot use this new one. None of them has new commits. They can fork again without problems.

I would like to hear suggestions on how to proceed.

Thank you.

Nerian
  • 15,901
  • 13
  • 66
  • 96

1 Answers1

4

You're going to want to look at git filter-branch, and more specifically, the --tree-filter option for it. For example:

git filter-branch --tree-filter "rm -r vendor/*" HEAD
Amber
  • 507,862
  • 82
  • 626
  • 550
  • I would like to add that things aren't "deleted officially" in git for 90 days. If you want your repo to shrink, you need to set the expiry date for garbage collection to immediate, garbage collect and then set the expiry for 90 days again. – Adam Dymitruk Sep 30 '11 at 00:37
  • Either `git gc --prune=now` (clearing the reflogs first if they are on), or just re-clone the repo and use the new clone (which will automatically be a new minimal repo, since unused stuff isn't cloned). – Amber Sep 30 '11 at 00:50
  • I tried this in my local repo and it worked. But when I do git status I see that "Your branch and 'origin/master' have diverged, # and have 181 and 181 different commit(s) each, respectively." – Nerian Sep 30 '11 at 01:00
  • So I can rewrite the history of my local repo, but is there any way to push those changes to github? – Nerian Sep 30 '11 at 01:01
  • ...besides creating a new repo. – Nerian Sep 30 '11 at 01:01
  • 1
    You can `git push origin HEAD --force` to force GitHub to take the new version instead of the existing. – Amber Sep 30 '11 at 04:02
  • @amber: And once I push those changes, will the public repo garbage collect all the unused blobs? That is, the online repo will be of the same size as my local repo? – Nerian Sep 30 '11 at 11:11
  • That depends on how GitHub handles it. I believe they gc their repositories pretty aggressively. – Amber Sep 30 '11 at 16:02