Skip to content

Instantly share code, notes, and snippets.

@jatcwang
Created December 9, 2016 04:27
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 jatcwang/7257a762f2fbcdeae69e0cb0ba3e9df7 to your computer and use it in GitHub Desktop.
Save jatcwang/7257a762f2fbcdeae69e0cb0ba3e9df7 to your computer and use it in GitHub Desktop.
Git subtree split a directory into new repository
Imagine this project structure
proj_a/
lib_b/ ... contents you want to split
First create a new git repository somewhere in the file system
mkdir /lib_b
cd /lib_b
git init
# Allow pushing to currently checked out branch
git config receive.denyCurrentBranch ignore
# back to proj_a
cd /proj_a
# Setup remote
git remote add lib_b /lib_b
# Split the history for lib_b subdirectory and push into lib_b remote's master branch
git subtree push --prefix=lib_b lib_b master
# ... handle further changes in /lib_b, with full history for that module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment