Skip to content

Instantly share code, notes, and snippets.

@jwinder
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwinder/a0104faff8888d1316c9 to your computer and use it in GitHub Desktop.
Save jwinder/a0104faff8888d1316c9 to your computer and use it in GitHub Desktop.
github-split.sh
#!/bin/sh
# Usage: github-split org/project directory new-project
REPO=$1
FOLDER=$2
NEW_REPO=$3
function usage() {
echo ""
echo "Usage: $0 <repo> <folder> <new_repo>"
echo "\trepo - The source repo to pull from, e.g. org/project-name"
echo "\tfolder - The folder to split"
echo "\tnew_repo - The new repo name, e.g. new-project-name"
exit 1
}
[ $# -le 2 ] && usage
echo "Getting the repo and putting it in /tmp"
git clone git@github.com:$REPO /tmp/$NEW_REPO
cd /tmp/$NEW_REPO
git pull
echo "Removing the remote origin, for safety"
git remote rm origin
echo "Filtering by the sub-directory and moving it into the main repo directory"
git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter $FOLDER master -- -all -- --tags
echo "\n\nNow you can add a new remote to this repo. Don't forget to push with --tags!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment