Skip to content

Instantly share code, notes, and snippets.

@juanje
Created November 22, 2011 17:52
Show Gist options
  • Save juanje/1386361 to your computer and use it in GitHub Desktop.
Save juanje/1386361 to your computer and use it in GitHub Desktop.
Split a subdirectory into a new Git repo
# You need to install the command git-subtree from here:
# https://github.com/apenwarr/git-subtree
# Let's say you got a subdirectory 'lib-abc' under 'project' git repo that you like to
# split into a new repository
# First you need to create a bare repository, i.e. a Github project called 'lib-abc'
# Your new remote could be somethings like 'git@github.com:yourname/lib-abc.git'
cd project/
git subtree split --prefix=lib-abc -b new_branch
# add the lib-abc's remote at Github
git remote add split git@github.com:yourname/lib-abc.git
# push the splitted branch as a master to Github
git push split new_branch:master
# That's all :-)
# Now some clean up
git branch -D new_branch
git remote rm split
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment