Ilya
Ilya

Reputation: 5613

How to separate a small library out of a big Git tree

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.

Upvotes: 4

Views: 86

Answers (2)

Fwolf
Fwolf

Reputation: 691

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.

Upvotes: 3

VonC
VonC

Reputation: 1326872

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").

Upvotes: 3

Related Questions