Git: create a mirror/fork repository with reduced history

Viewed 199

Assume there is a big Git repo Orig under an active development and with a long history. That repository has some big files too but does not use the git-lfs. I don't control that repo, particularly I can't migrate it to the git-lfs.

I'd like to create a fork repository (Fork) with the following properties:

  1. I can easily merge changes from the Orig development into the corresponding Fork branches and in my custom branches based on those branches (cherry-picking each change doesn't count as "easily").
  2. I can easily create pull requests to the Orig repo with some of my changes in the Fork (less important than #1 but nice to have)
  3. I want to have the history of the Fork much reduced in terms of the depth (smaller clone)
  4. I want to have the history of the Fork much reduced in terms of big files because I want to host my Fork on the GitHub. This is an issue because git-lfs migrate rewrites the history.

Accidentally just solving #3 will probably fix #4 because there are just a few really big files that would require git-lfs and they all are not in the part of the history I really want to keep in my Fork.

Achieving just #4 without #3 (but still getting #1 and #2) is acceptable because #4 is really a blocker while #3 is only nice-to-have.

Things I don't really need:

  • I don't need to keep all the Orig historical branches in my Fork. I really need the master. A few recent feature branches as well would be really nice.
  • It is acceptable for the initial setup to be complicated and time-consuming as long as the main workflow after that works smoothly.

Some obvious things that I believe do not work:

  • Do git-lfs migrate to fix #4 and push it to the GitHub. This seems to break #1 and #2 since it creates a totally new history with no connection to the original one so I can not easily merge new changes from the Orig to Fork.
  • Create a shallow copy and push it as a new repository to the GitHub. This fixes #4 and probably #3 but again breaks #1 and #2.

I suspect there is no good solution to this problem with how git hashes work. At least Partial repository mirror of git repositories and Git mirror of non-LFS repo to LFS-repo do not look really promising. But I still have a hope it can be done with some git-magic (or that somehow the things have changed over the last few years).

0 Answers
Related