Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save axelinternet/3c6c81448fd902bcac046752e648e100 to your computer and use it in GitHub Desktop.
Save axelinternet/3c6c81448fd902bcac046752e648e100 to your computer and use it in GitHub Desktop.
Push to multiple remotes

Add a new remote called all that we'll reference later when pushing to multiple repositories:

  $ git remote add all git://original/repo.git
  $ git remote -v
  all git://original/repo.git (fetch)               <-- ADDED
  all git://original/repo.git (push)                <-- ADDED
  origin  git://original/repo.git (fetch)
  origin  git://original/repo.git (push)
  $ git config -l | grep '^remote\.all'
  remote.all.url=git://original/repo.git            <-- ADDED
  remote.all.fetch=+refs/heads/*:refs/remotes/all/* <-- ADDED

Then let's add a pushurl to the all remote, pointing to another repository:

  $ git remote set-url --add --push all git://another/repo.git
  $ git remote -v
  all git://original/repo.git (fetch)
  all git://another/repo.git (push)                 <-- CHANGED
  origin  git://original/repo.git (fetch)
  origin  git://original/repo.git (push)
  $ git config -l | grep '^remote\.all'
  remote.all.url=git://original/repo.git
  remote.all.fetch=+refs/heads/*:refs/remotes/all/*
  remote.all.pushurl=git://another/repo.git         <-- ADDED

Here git remote -v shows the new pushurl for push, so if you do git push all master, it will push the master branch to git://another/repo.git only. This shows how pushurl overrides the default url (remote.all.url).

Now let's add another pushurl pointing to the original repository:

  $ git remote set-url --add --push all git://original/repo.git
  $ git remote -v
  all git://original/repo.git (fetch)
  all git://another/repo.git (push)
  all git://original/repo.git (push)                <-- ADDED
  origin  git://original/repo.git (fetch)
  origin  git://original/repo.git (push)
  $ git config -l | grep '^remote\.all'
  remote.all.url=git://original/repo.git
  remote.all.fetch=+refs/heads/*:refs/remotes/all/*
  remote.all.pushurl=git://another/repo.git
  remote.all.pushurl=git://original/repo.git        <-- ADDED

You see both pushurls we added are kept. Now a single git push all master will push the master branch to both git://another/repo.git and git://original/repo.git.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment