As part of our current workflow we pre-clone certain git repos into user homedirs at the time of creation. However, as these repositories grow and user count increases the disk usage has become more and more problematic.
I am attacking this on two fronts:
- Existing repos with no changed files get
git reset --hard $first_commit
which reverts them to a much tinier initial state. The usualgit pull
on login brings them up to current as always. - New users get repos that start at
$initial commit
and can get brought up to current viagit pull
.
While I've come up with a solution for #1 and submitted it for review I'm having trouble coming up with a solution for #2 that doesn't incur a lot of IO overhead.
The simple solution would just be:
git clone /opt/git/app.git /home/user/app && \
git -C /home/user/app reset --hard $first_commit
However, checking out the full working tree only to delete it incurs a lot of extra IO, which is a valid concern when a new application server is created along with all of the requisite users.
I've tried the following based on this answer, but the resulting repo isn't properly set up to pull from origin/master
:
git init /home/user/app
git -C /home/user/app remote add origin /opt/git/app.git
git -C /home/user/app fetch origin $first_commit
It doesn't seem to have any branch set at all somehow, and the following is missing from .git/config
:
[branch "master"]
remote = origin
merge = refs/heads/master
Thanks in advance.