Skip to content

Instantly share code, notes, and snippets.

@mongris
Created February 21, 2013 11:42
Show Gist options
  • Save mongris/5004194 to your computer and use it in GitHub Desktop.
Save mongris/5004194 to your computer and use it in GitHub Desktop.
Detach subdirectory into separate Git repository from: http://stackoverflow.com/a/9510944
#!/bin/bash
#
# git-subdir.sh
#
git clone --no-hardlinks $1 $2
cd $2
git filter-branch --subdirectory-filter $2 --prune-empty --tag-name-filter cat HEAD -- --all
git reset --hard
git remote rm origin
refbak=$(git for-each-ref --format="%(refname)" refs/original/)
if [ -n "$refbak" ];then
echo -n $refbak | xargs -n 1 git update-ref -d
fi
git reflog expire --expire=now --all
git repack -ad
git gc --aggressive --prune=now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment