4

There's a small library in some big project (in a git repo), that I believe can be factored out of this big project, and so benefit people who need just the small library.

The small library is a subdirectory in the big project.

What's the best way to do it? Specifically, I'm asking how not to lose ties to the parent project, so I can:

  1. keep the history
  2. benefit from the upstream improvements,
  3. contribute to upstream improvements,
  4. (and of course, still be able to do however little changes I need to factor the library out of the big project's structure)

I was thinking of just forking and then moving and deleting items with git, but I'm not sure whether it'll preserve sufficient ties to the parent project.

Ilya
  • 5,533
  • 2
  • 29
  • 57

2 Answers2

3

forking and then moving and deleting items with git, but I'm not sure whether it'll preserve sufficient ties to the parent project.

Once you have done that, you would still need to declare that new repo (for the small library) as a submodule in your big project repo (see git submodule).

That way, you will keep an exact reference to a specific version of that library repo, and will still be able to contribute from said library (see "true nature of submodules").

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • If you can get the big project maintainers to (agree to) separate it into a submodule, that would probably be the simplest solution. But submodules have their problems. The [git subdir page](http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/) seems explains them and the advantages of using git-subdir. I have to admit I never used it, but the concept sounds more suitable for this scenario – m0she Dec 04 '13 at 17:27
  • @m0she git subtree is the "old way" of managing configuration and dependencies. I would certainly *not* recommend that. – VonC Dec 04 '13 at 18:32
3

Use git subtree, you can:

  1. keep the history --> yes, both in upstreem and subtree repo
  2. benefit from the upstream improvements --> yes, git subtree pull
  3. contribute to upstream improvements --> yes, git subtree push
  4. have some different with upstream --> could, use a branch sync with upstream and another branch for other usage

The better than submodule is, your upstream will keep same as before, nothing changed in it.

Fwolf
  • 671
  • 4
  • 8