Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit c1e599cc20ab3a98317e97f1dbdda39d2eca5c50 1 parent 94aa0e1
Sean S authored
42 _posts/2013-03-16-git-how-do-i-push-to-two-remotes-at-once.md
Source Rendered
... ... @@ -0,0 +1,42 @@
  1 +---
  2 +layout: post
  3 +disqus_id: post-4
  4 +
  5 +title: "git: how do I push to two remotes at once?"
  6 +author: crdx
  7 +tags: code git
  8 +---
  9 +
  10 +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.
  11 +
  12 +If you try to add a new url to your remote via the command line:
  13 +
  14 + $ git remote add origin ssh://git@bitbucket.org/crdx/crdx.org.git
  15 + fatal: remote origin already exists.
  16 +
  17 +Turns out it can be done, but it's not made very obvious and requires some manual config editing.
  18 +
  19 +First, edit your repository's local configuration:
  20 +
  21 + git config --local -e
  22 +
  23 +Find the section for your desired upstream:
  24 +
  25 + [remote "origin"]
  26 + url = git@github.com:crdx/crdx.org.git
  27 + fetch = +refs/heads/*:refs/remotes/origin/*
  28 +
  29 +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.
  30 +
  31 +In my case it becomes:
  32 +
  33 + [remote "origin"]
  34 + url = git@github.com:crdx/crdx.org.git
  35 + url = ssh://git@bitbucket.org/crdx/crdx.org.git
  36 + fetch = +refs/heads/*:refs/remotes/origin/*
  37 +
  38 +Now `push` will push to both:
  39 +
  40 + git (master)> push
  41 + Everything up-to-date
  42 + Everything up-to-date

0 comments on commit c1e599c

Please sign in to comment.
Something went wrong with that request. Please try again.