Skip to content

Instantly share code, notes, and snippets.

@pk
Created March 18, 2010 15:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save pk/336478 to your computer and use it in GitHub Desktop.
Save pk/336478 to your computer and use it in GitHub Desktop.
Extract directory from the GIT repo to the standalone GIT repo.
#!/bin/bash
FROM=$1
TO=$2
echo "Spliting '$TO' from '$FROM'"
git clone --no-hardlinks $FROM $TO
cd $TO
git filter-branch --subdirectory-filter $TO HEAD -- --all
git reset --hard
git gc --aggressive
git prune
echo "DONE!"
@rip747
Copy link

rip747 commented Oct 6, 2010

thank you for this gist. it really made understanding how to extract a directory out of an existing repo very easy. one thing i would like to add through is that afterwards you want to issue a

git remote rm origin

since origin is still pointing to the original repo that you extracted from.

@pk
Copy link
Author

pk commented Oct 7, 2010

Cool it helped. I'm not author, it's based on some solution I found on the stackoverflow I think. I think I did changed the origins manually later but removing it is safer, yep.

@Blaisorblade
Copy link

Here's a relevant question on StackOverflow (probably the source of the above script), with additional tips and variations:
http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment