Adding a second or multiple remotes to an existing git repository

Github does not provide free private git repos. So I use gitlab to host my own git server, and when I decide to go public, I switch to Github, or use Github as a second remote.

Here’s how you can add a second remote to your existing git repo.

Typically the existing remote is labelled as ‘origin’. In the example below, you’ll be adding a new remote labelled ‘github’.

As a first step, got to Github and create a new git repo. Get the github url (the git@ url, not the https one, since the latter asks for a password while pushing)

At the bash prompt, cd to the directory of your existing remote

cd /path/to/gitrepo
git remote add github [email protected]:droidzone/wordpress_plugin_updater.git
git push github master

To change a remote:

git remote set-url github [email protected]:droidzone/wordpress_plugin_updater.git

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.