|
| 1 | +# Reducing Git Repo Size |
| 2 | +`forem` clones are currently 1.5G due to old vendor/cache gem's committed to the |
| 3 | +git repo. Use the steps below to reduce your clone size by 80% -- meaning |
| 4 | +faster _clone_ , deploy , _log_ and less disk usage |
| 5 | + |
| 6 | +**caveat**: This uses a "partial clone" method which fetches a complete working |
| 7 | +tree but avoids cloning older objects from the history . See |
| 8 | +[this guide](https://about.gitlab.com/blog/2019/03/13/partial-clone-for-massive-repositories/) |
| 9 | +and the [git docs on partial clones](https://git-scm.com/docs/partial-clone) for a |
| 10 | +more complete command and config overview. |
| 11 | + |
| 12 | +## Preferred Method for New Clones |
| 13 | +``` |
| 14 | +# do a partial clone |
| 15 | +$ git clone --single-branch --branch main --filter=blob:none git@github.com:forem/forem.git |
| 16 | +``` |
| 17 | +### Test to Confirm the Repo Size |
| 18 | +``` |
| 19 | +# your repo will be about 300MB instead of 1500MB |
| 20 | +$ du -sh . |
| 21 | +280M . |
| 22 | +``` |
| 23 | + |
| 24 | +## Existing Clones (for experts) |
| 25 | +You can clean up existing clones, but with this method you will have to rebase |
| 26 | +any changes before submitting PRs. Added work will be required. |
| 27 | + |
| 28 | +#### 1. Update the ref config in `.git/config` |
| 29 | +update `fetch` and `partialCloneFilter` |
| 30 | +``` |
| 31 | +[remote "upstream"] |
| 32 | + url = git@github.com:forem/forem.git |
| 33 | + fetch = +refs/heads/main:refs/remotes/upstream/main |
| 34 | + promisor = true |
| 35 | + partialclonefilter = blob:none |
| 36 | +``` |
| 37 | +#### 2. Prune Old Objects Out of your Clone |
| 38 | +Prerequisite: [git-filter-repo](https://github.com/newren/git-filter-repo) needs to be installed |
| 39 | +``` |
| 40 | +git filter-repo --force --invert-paths --path-glob 'vendor/cache' |
| 41 | +``` |
0 commit comments