I have most of my private repositories hosted on BitBucket.org. They provide free space for private repos. GitHub requires a paid plan to host private repos. I have lots of private repos. However, it seems that everyone wants to see coding samples. GitHub no longer requires a paid plan to host public (open source) repositories, so why not take a fresh look?
I don’t want to show off all my mistakes in the public GitHub account, so I’m keeping the private BitBucket account. How do I push additional BitBucket snapshots that are sort-of cleaned up to the public GitHub account?
Step 1: Set up a public GitHub repository
That’s easy. I already have a GitHub account that I used when I was taken the Berkeley Coursera class. The account was private while I was taking the class, but became public when the class ended. Setting up a new repo in GitHub is easy and they provide help pages if you have questions.
Step 2: Figure out how to push the local repos
I already use GitHub Desktop (for Mac) to clone tutorials. In the end, I decided not to use it to clone and push the BitBucket repos to GitHub because I was concerned the alias to BitBucket would be overwritten.
Step 2a: Use the command line interface to create another alias
GitHub (and BitBucket) will automatically create a remote alias when creating a remote repository and use it to push snapshots up to that repository. I’m already using that alias (origin) and was concerned that GitHub Desktop would overwrite the alias to github if I reset it using GitHub Desktop. However, I can use the CLI to create a new alias.
> git remote add github firstname.lastname@example.org:rachavez/tournament-score-keeper.git
When I check the aliases using “git remote -v”, I see another set of aliases pointing to a different server.
So, while I’m stuck with dead end and intermediate steps, commits go to BitBucket. Once I figure everything out and arrive at a good stopping point, the commits all get pushed as a block to GitHub.
> git push github master
I can live with it. Even better, I noticed in SourceTree (Atlassian/BitBucket’s Mac desktop app) that the new alias appears in the remotes list. Potentially, I could update SourceTree settings to go back and forth between both repositories. Interesting.