Fun with Git Branches

An organization I work with stored several little-used projects as branches in a single git repository as a way to save money on github private repos. They've now got more repos available, and want one of these projects split out into its own repo. This is a somewhat annotated session of how that process was achieved.

$ git clone # checkout the multi-branch repo
$ mkdir torontomap # make a new home
$ cd torontomap
$ git init # make the new home a repo
$ cd ../labs # go to the old repo
$ git branch -a # find out what branches we have
$ git checkout -b torontomap remotes/origin/torontomap # check out the branch we want locally
$ git checkout -b torontomap-dev remotes/origin/torontomap-dev # same project, dev branch
$ git push ../torontomap/ torontomap:master # boom - denied
$ git push ../torontomap/ torontomap # correct syntax
$ git push ../torontomap/ torontomap-dev # second param is the local branch name
$ cd ../torontomap/
$ git checkout torontomap # master is completely empty, change to new branch ...
$ git branch -m master # this branch becomes master
$ git checkout torontomap-dev # get our other branch
$ git branch -m dev # rename the other branch
$ git move torontomap/* . # restructure ... won't bore you with the details
$ du -sh
$ git gc --aggressive --prune=now # recommended by a friend
$ du -sh
... # same size as previously ... garbage collection not needed?
$ git commit -a
$ # and repeat the same clean-up on master
$ git log torontomap-dev # see the log for another branch, clone the commit message (since I did the same thing on both branches)

Finally, push the new repo up to github. Turned out to be surprisingly easy.