Skip to content

Instantly share code, notes, and snippets.

@oodavid
Created June 22, 2017 12:09
Show Gist options
  • Save oodavid/b4720d9a6c8fd8a02a46381de226d67e to your computer and use it in GitHub Desktop.
Save oodavid/b4720d9a6c8fd8a02a46381de226d67e to your computer and use it in GitHub Desktop.
Create a new repo from a directory within an existing repo

Make sure you have this git alias

git config --global alias.clone-branches '! git branch -a | sed -n "/\/HEAD /d; /\/master$/d; /remotes/p;" | xargs -L1 git checkout -t'

Clone the remote, pull all branches, change the remote, filter your directory, push

git clone [email protected]:user/existing-repo.git new-repo
cd new-repo
git clone-branches
git remote rm origin
git remote add origin [email protected]:user/new-repo.git
git remote -v
git filter-branch --subdirectory-filter my_directory/ -- --all
git push --all
git push --tags
@schlueter
Copy link

git clone-branches isn't implemented in git 2.35.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment