Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

post: "git: how do I push to two remotes at once?"

  • Loading branch information...
commit c1e599cc20ab3a98317e97f1dbdda39d2eca5c50 1 parent 94aa0e1
@crdx authored
Showing with 42 additions and 0 deletions.
  1. +42 −0 _posts/2013-03-16-git-how-do-i-push-to-two-remotes-at-once.md
View
42 _posts/2013-03-16-git-how-do-i-push-to-two-remotes-at-once.md
@@ -0,0 +1,42 @@
+---
+layout: post
+disqus_id: post-4
+
+title: "git: how do I push to two remotes at once?"
+author: crdx
+tags: code git
+---
+
+Once upon a time I was going to push to both BitBucket and GitHub and I didn't fancy increasing the number of commands required to push my code to two. That's one too many.
+
+If you try to add a new url to your remote via the command line:
+
+ $ git remote add origin ssh://git@bitbucket.org/crdx/crdx.org.git
+ fatal: remote origin already exists.
+
+Turns out it can be done, but it's not made very obvious and requires some manual config editing.
+
+First, edit your repository's local configuration:
+
+ git config --local -e
+
+Find the section for your desired upstream:
+
+ [remote "origin"]
+ url = git@github.com:crdx/crdx.org.git
+ fetch = +refs/heads/*:refs/remotes/origin/*
+
+Now add a new `url` entry for your other remote. This looks wrong because it looks like it's overwriting it. Well, apparently it's not.
+
+In my case it becomes:
+
+ [remote "origin"]
+ url = git@github.com:crdx/crdx.org.git
+ url = ssh://git@bitbucket.org/crdx/crdx.org.git
+ fetch = +refs/heads/*:refs/remotes/origin/*
+
+Now `push` will push to both:
+
+ git (master)> push
+ Everything up-to-date
+ Everything up-to-date
Please sign in to comment.
Something went wrong with that request. Please try again.