-1

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:

  1. Existing repos with no changed files get git reset --hard $first_commit which reverts them to a much tinier initial state. The usual git pull on login brings them up to current as always.
  2. New users get repos that start at $initial commit and can get brought up to current via git 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.

Community
  • 1
  • 1
Sammitch
  • 30,782
  • 7
  • 50
  • 77
  • If you don't need any of the git history, would building a binary of your project and simply downloading that work? – Andy Ray Mar 29 '17 at 00:34
  • @AndyRay nope. This is a multi-developer environment with a bit of a janky workflow. – Sammitch Mar 29 '17 at 01:07

1 Answers1

1

Use git branch --set-upstream-to to set master’s upstream:

git init
git remote add origin /opt/git/app.git
git fetch origin
git reset --hard "$first_commit"
git branch --set-upstream-to=origin/master
Ry-
  • 218,210
  • 55
  • 464
  • 476