brunoos
brunoos

Reputation: 81

How to clone partial repository in git to save disk space

I've a large repository with disk space of around 5Gb. I only need few folders from this repository and I'm able to do sparse checkout for those folders. But the diskspace consumption of .git folder is still 5GB. So, is there any way to save disk space and only clone the required folders or any other way?

Steps for my sparse checkout:

git init
git config core.sparsecheckout true
touch .git/info/sparse-checkout
echo path/to/folder1 >> .git/info/sparse-checkout
echo path/to/folder2 >> .git/info/sparse-checkout
git remote add -f <branch name> <url>            <==taking too much memory here
git checkout <tag>

Upvotes: 4

Views: 2736

Answers (1)

VonC
VonC

Reputation: 1323203

The only other way (beside trying to trim down the .git size with aggressive git gc) would be to:

  • isolate this folders in a dedicated branch (in the git repo of the server side)
  • push that branch in a new repo (still on the server side)
  • clone that new repo (on your local machine)

That way, you are dealing with an intermediate repo which contains only the history of that branch with the folders you are interested in.
Yet, an integrator can clone the main repo, fetch the second repo (the one with only one branch) and reintegrate back any modification you would have published on the second repo.

Upvotes: 1

Related Questions