Created
April 9, 2012 13:21
-
-
Save uliwitness/2343351 to your computer and use it in GitHub Desktop.
Shell script to extract a folder from a git repository to make a new repository with only the history for that folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# param 1 is path to root of repository to clone | |
# param 2 is folder to clone to. The folder's name must be the | |
# same as the folder to be extracted from the repository at param 1. | |
GIT='/Applications/Xcode.app/Contents/Developer/usr/bin/git' | |
$GIT clone --no-hardlinks "$1" "$2" | |
cd "$2" | |
$GIT filter-branch --subdirectory-filter "`basename $2`" HEAD #-- --all | |
# "-- --all" copies along tags and branches | |
$GIT reset --hard | |
$GIT gc --aggressive | |
$GIT prune | |
$GIT remote rm origin | |
$GIT update-ref -d refs/original/refs/heads/master | |
$GIT reflog expire --expire=now --all | |
$GIT repack -ad |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment