How to split out a piece of a package into a separate package

package
git

#1

I need to split out a piece of functionality into a separate package. What’s the best way to do this while preserving the git history?

Since I know there are several success stories, I thought it would be useful to codify this here (even though it’s more a git issue than a Julia one).


#2

To answer my own question:

  1. Make a new copy of the package using git clone OLD NEW

  2. Change to the NEW directory

  3. To keep only certain subdirectories in the new package, use the following single-line git command, listing those subdirectories that you wish to keep (in this example, src/root_finding and test/root_finding_tests):
    git filter-branch --index-filter 'git rm --cached -qr --ignore-unmatch -- . && git reset -q $GIT_COMMIT -- src/root_finding test/root_finding_tests' --prune-empty -- --all

  4. Make a new remote repository (e.g. using hub create) and push the new package there.

  5. In the repository for the old package, delete the files that have been moved, using git rm.


#3

I have a question.

Wouldn’t this mean that users that Pkg.add both packages will also download both identical histories twice (and also take twice as much memory in disk)?

Is splitting without keeping history allowed?


#4

Will not be a problem in a while (Pkg3) since using git repos will not be the common case.