Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 0rbadvent/696855afd15f99b02b934e69d17f9d5e to your computer and use it in GitHub Desktop.
Save 0rbadvent/696855afd15f99b02b934e69d17f9d5e to your computer and use it in GitHub Desktop.
Given a subdirectory extract separate repo out of an existing one
# Simple
git filter-branch --prune-empty --subdirectory-filter foobar/ --tag-name-filter cat -- --all
# Complex
# (Ref.: http://stackoverflow.com/a/17867910/11895,
# http://stackoverflow.com/a/19957874/11895)
git filter-branch -f --prune-empty --index-filter \
'git rm --cached --ignore-unmatch -r -q -- . ; \
git reset -q $GIT_COMMIT -- .gitignore README.md foo/ bar/' \
-- --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment