Created
October 1, 2015 19:23
-
-
Save spectra/8bf5c767148c3c6e7f75 to your computer and use it in GitHub Desktop.
Extract a git directory as a separated project
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
#!/bin/bash | |
SUBDIR=$1 | |
if [ "$SUBDIR" = "" ]; then | |
echo "You have to enter a subdir as first arg" | |
exit -1 | |
fi | |
if [ ! -e $SUBDIR ]; then | |
echo "$SUBDIR must exist. Are you in the repo root?" | |
exit -1 | |
fi | |
echo "Removing old origin" | |
git remote rm origin | |
echo "Filtering only the requested subdir ($SUBDIR)" | |
git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter $SUBDIR HEAD | |
echo "Purges repo of all unrelated references" | |
git reset --hard | |
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d | |
git reflog expire --expire=now --all | |
git gc --aggressive --prune=now | |
echo "All done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment