How to Configure Git to Push to Multiple Remotes
You might have seen the news today that GitHub is planning on implementing community guidelines, and wanted to branch out. I personally don't think anything I make will ever fall into "hateful speech", but you can never be too safe.
Anyway, now to the meat. How to do it!
First off, choose where you're going to have mirrors. I chose GitLab and BitBucket. Both of these have import functions. First thing you should do is import all your repositories.
Next, we're going to set up SSH keys. I did this on Windows, but all of this is the same on any platform. Probably just follow your service's guide to generating ssh keys, except as you are using multiple, make sure to set the key location to something that's not default. I had mine set to 'id_github', 'id_gitlab' and 'id_atlassian'. Add these keys to the services. (Ignore the bit in the GitHub about adding it to the agent, we do that later.)
Next we set up ssh to use these keys properly. In your ssh config (~/.ssh/config), add these lines (Replacing the location of your identity file):
Now for the tedious bit. Adding these as alternate clone loactions. First off, you have to find where all the git repos on your disk are. Luckily, all mine were in a single folder.
Then, you open your terminal in their folder. I'm going to assume that you only have one push location at this point, being github. To verify, you can run 'git remote -v', and you should get this:
If that's what it looks like, great! Go ahead and continue.
This is what you'll have to run for each repo:
That's it! Maybe consider adding some features of the new git push target you just added. I quite like GitLab CI.
You can go ahead and test the implementation by adding some code and doing a 'git push -v'.
Edit: It has been brought to my attention that GitLab lets you do this natively. Oops.
Sources:
I used a fair few sources for this, but I was implementing this myself and didn't think of writing a post for it. I'll try look through history and find them.
git-scm book
GitHub and GitLab's ssh key guide
I'm sure I missed some, but this is about all I can get.