$ cd myproject
$ git remote add bitbucket ssh://git@bitbucket.org/user/myproject.git
$ git push bitbucket master
Every time we commit any changes, we need to push to both our original “origin” and our new remote “bitbucket”:
$ git push origin master
$ git push bitbucket master
You may add this as an alias to make things easier.
alias gpob="git push origin master && git push bitbucket master"
$ cd myproject
$ git remote set-url --add origin ssh://git@bitbucket.org/user/myproject.git
$ git push origin master
Everything up-to-date
Everything up-to-date
Of course silver lining has a cloud, and in this case, it is that while we can push to multiple URLs simultaneously, we can only fetch from the original origin (you can change this, but that is out of scope for this post).
To show all remotes use:
$ git remote -v show
Output should look something like this:
bitbucket git@bitbucket.org:user/myproject.git (fetch)
bitbucket git@bitbucket.org:user/myproject.git (push)
origin git@github.com:user/myproject.git (fetch)
origin git@github.com:user/myproject.git (push)
origin git@bitbucket.org:user/myproject.git (push)
Hattip to @ahmadawais for writing a tutorial on this.