Skip to content

Instantly share code, notes, and snippets.

@dgroomes
Last active September 8, 2020 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgroomes/d174cc33ea7786736e2b62afdfb602ab to your computer and use it in GitHub Desktop.
Save dgroomes/d174cc33ea7786736e2b62afdfb602ab to your computer and use it in GitHub Desktop.
Splitting out a Git repo from a Git repo

Splitting out a Git repo from a Git repo

Git ships with an advanced command called filter-branch which can be used to, among other things, split out a new Git repo from a larger Git repo. Unfortunately, the tool has issues and is officially not recommend by Git. They recommend https://github.com/newren/git-filter-repo as an alternative. git-filter-repo seems like it is worth exploring for use cases beyond the most basic happy path. Fortunately, I have only needed the basic happy path of "split out this sub-directory and all its commit history exactly as is into its own Git repo". For a good illustration of this use case, see https://docs.github.com/en/github/using-git/splitting-a-subfolder-out-into-a-new-repository.

The core command is:

git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME  BRANCH-NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment