Skip to content

Instantly share code, notes, and snippets.

@korya
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 korya/fcbea22b4f96ce9b14a2 to your computer and use it in GitHub Desktop.
Save korya/fcbea22b4f96ce9b14a2 to your computer and use it in GitHub Desktop.
Convert git repo subhistory to a separate git repo
  1. Clone

    git clone <remote-url> <dir>
    cd <dir>
    git remote rm origin
  2. Find a start commit of your history

    START=git log | grep ...
  3. Create new orphan branch

    git checkout --orphan new-root
    echo "This is a new repo" > README.md
    git commit -m "Initial commit" README.md
  4. Rebase

    git rebase --onto new-root ${START}~ master
  5. Cleanup & push

    git branch -D new-root
    git remote add origin <new-remote-url>
    git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment