Skip to content

Instantly share code, notes, and snippets.

@NuckChorris
Created October 6, 2016 05:04
Show Gist options
  • Save NuckChorris/31ea06f6a6c3734a9e84b1249e63352c to your computer and use it in GitHub Desktop.
Save NuckChorris/31ea06f6a6c3734a9e84b1249e63352c to your computer and use it in GitHub Desktop.

First, clone a new copy of your existing fork locally, and check out the branch you want to migrate to the split repos.

Run this beast, replacing branch-name-goes-here with your branch name (and doing the same for all future commands):

git filter-branch -f --prune-empty --subdirectory-filter server --msg-filter 'sed "s/^server: //" | ruby -e "puts ARGF.read.capitalize"' branch-name-goes-here

Congrats, you now have a branch with all the commit history for the server/ directory. Now we need to "rebase" it on top of the existing commits in the split server repo.

Run this to add the server as a second remote and check out the main branch on it:

git remote add server https://github.com/hummingbird-me/hummingbird-server
git fetch server
git checkout -b server-future server/the-future

So now we have two branches: the canonical server-future from the server repo, and your own branch, which is pretty darn similar.

We need to copy the commits from your branch onto the the-future branch. So run this and figure out what the first and last commits you're interested are, noting their SHAs:

git log branch-name-goes-here

And copy it onto server-future by running this, filling in the oldest commit SHA and the newest SHA:

git cherry-pick oldest..newest

Awesome! Now we have your branch, on top of the existing server history. Now, rename the branch to the original name:

git branch -D branch-name-goes-here
git checkout -b branch-name-goes-here

Fork the server repo and add it as a remote in this terror we've wrought so far:

git remote add my-server https://github.com/YOURUSERNAME/hummingbird-server

And push your branch

git push my-server branch-name-goes-here

Congrats. You're finally done with this hellish process.

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