Skip to content

Instantly share code, notes, and snippets.

@lindhe
Created October 23, 2023 13:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindhe/5ded491109a6ffda113eb6a210feb0a2 to your computer and use it in GitHub Desktop.
Save lindhe/5ded491109a6ffda113eb6a210feb0a2 to your computer and use it in GitHub Desktop.
Splitting a repo

Splitting a repo

Here is a recepie for how to split a repo.

If you have a repo that you want to split in twine, life can be simple! At least if you have been a good boy and kept the different parts in different subdirectories to begin with…

This is all you have to do:

  1. Make a copy of the original repo.

  2. Run git rebase -i --root and copy all the lines into history.log

  3. Then run

    git log --pretty='%h' ./some_path > drop.log
    for commit in $(cat ./drop.log); do sed -i "s/pick \(${commit}\)/drop \1/" ./history.log; done
  4. Then simply run git rebase -i --root again and replace all the lines with the contents of history.log

  5. Lastly, set the origin remote to the new repo URL:

    git remote set-url origin https://git.example.com/foo/bar.git
    git fetch
    git push

https://youtu.be/M7FIvfx5J10

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