Last active
August 29, 2015 14:04
-
-
Save jwinder/a0104faff8888d1316c9 to your computer and use it in GitHub Desktop.
github-split.sh
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/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