Can a project have multiple origins?

Chris Dutrow picture Chris Dutrow · Jul 27, 2012 · Viewed 78.2k times · Source

Can a project have two (or more) "origins" in Git?

I would like to push a single project to both github and a Heroku server.

Specifically, this error appears when adding the github repository:

$ git remote add origin https://github.com/Company_Name/repository_name.git
fatal: remote origin already exists.

Answer

meagar picture meagar · Jul 27, 2012

You can have as many remotes as you want, but you can only have one remote named "origin". The remote called "origin" is not special in any way, except that it is the default remote created by Git when you clone an existing repository. You can configure a second remote, push to/pull from that remote, and setup some branches to track branches from that remote instead of origin.

Try adding a remote called "github" instead:

$ git remote add github https://github.com/Company_Name/repository_name.git

# push master to github
$ git push github master

# Push my-branch to github and set it to track github/my-branch
$ git push -u github my-branch

# Make some existing branch track github instead of origin
$ git branch --set-upstream other-branch github/other-branch