Skip to content

Instantly share code, notes, and snippets.

@rmurphey
Forked from cowboy/filter_subdir.sh
Created October 21, 2012 17:58
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 rmurphey/3927862 to your computer and use it in GitHub Desktop.
Save rmurphey/3927862 to your computer and use it in GitHub Desktop.
Make a new repo from a subdirectory of an original repo
# Please don't just RUN this. Do it step-by-step.
user=bocoup
orig_repo=training
new_repo=training-jquery
subdir=jquery-conference
# Pull down the original repo.
git clone git@github.com:$user/$orig_repo.git $new_repo
# Repo, I'm in you.
cd $new_repo
# Rewrite history, removing everything but files in the "subdir" directory.
# This moves all those files into the root as well. Not sure that this
# handles all refs, not sure that I care.
git filter-branch --subdirectory-filter $subdir -- --all
# Verify there aren't any missing renamed files, et (per man page).
git log --name-only --follow --all -- filename
# In the GitHub admin, create a new repo for "user" with name "new_repo".
# Remove the "orig_repo" origin remote.
git remote rm origin
# Add the new "new_repo" origin remote.
git remote add origin git@github.com:$user/$new_repo.git
# Push to GitHub.
git push -u origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment