Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: Checkout branch and prune everything related to previous checkout (incl. git-lfs remains) #3499

Closed
mloskot opened this issue Jan 28, 2019 · 4 comments

Comments

@mloskot
Copy link
Contributor

mloskot commented Jan 28, 2019

(The problem was also posted to Git mailing list and StackOverflow, but without any responses. So, I'm forwarding it here (or is there any Git LFS forum?))

I have a repo of a superproject with number of submodules. lots of files of both are in Git LFS.

The repo comes with multiple long-lived release branches.

Problem

The complete clone transfers 20 GB of Git and Git LFS objects.

Checkout of master deflates the total repo to 40 GB in total, that is the objects and the working tree files together.

Let's consider three separate clones as canonical way to create three working copies, one per the long-lived branch:

git clone --branch master      --recursive --jobs 8 https://repo repo_master
git clone --branch release/1.0 --recursive --jobs 8 https://repo repo_release1
git clone --branch release/2.0 --recursive --jobs 8 https://repo repo_release2

I'm trying to work out a network-optimised equivalent of the above:

  • clone once with the default master checked out
  • make multiple copies of the cloned repo
  • checkout release branches

Questions

  1. How to checkout an existing branch fetched from remote, delete the previous branch and clean up any remains?

  2. How to clean up everything related to the previously checked out master and its working tree, any cached previous LFS downloads etc.?

But, to keep the history of origin/master.

Solution Prototype

Here is what I have come up with for the the network-optimised workflow:

git clone --branch master --recursive --jobs 8 https://repo repo_master

cp -a repo_master repo_release1
cp -a repo_master repo_release2

cd repo_release1
git checkout -b release/1.0 --track origin/release/1.0

git pull
git submodule update --init --recursive --jobs 8

git branch -D master

git lfs prune
git submodule foreach --recursive git lfs prune

git lfs checkout
git submodule foreach --recursive git lfs checkout

Questions to Prototype

Does it look correct or any steps are missing/redundant?

Does it make sense to run any of these, at which point?

git gc --aggressive --prune=now
git submodule foreach --recursive git gc --aggressive --prune=now

Please, assume, no new commits will happen locally between the git clone --branch master ... and cp -a repo_master ...

@bk2204
Copy link
Member

bk2204 commented Feb 4, 2019

I think this approach seems fine. I don't think it's necessary to run a git gc here, and it likely wouldn't have an effect due to the reflog anyway.

@bk2204 bk2204 closed this as completed Feb 4, 2019
@mloskot
Copy link
Contributor Author

mloskot commented Feb 4, 2019

@bk2204 Thank you! (FYI, There is bounty offered for this question on StackOverflow, ending in 3 hours :-))

@bk2204
Copy link
Member

bk2204 commented Feb 5, 2019

I will, unfortunately, be unable to claim it, but thanks for pointing it out.

@mloskot
Copy link
Contributor Author

mloskot commented Feb 5, 2019

@bk2204 I see. I've taken the liberty to forward your answer to SO, https://stackoverflow.com/a/54539218/151641 for some closure of the story :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants