6

I've create a clone of this repository. If I run the following command, I see that my local repo is configured to use my clone to fetch/pull, as expected.

$ git remote show origin
* remote origin
  Fetch URL: https://github.com/domurtag/airbrake-grails.git
  Push  URL: https://github.com/domurtag/airbrake-grails.git

I would like my local repo to instead fetch from the master repo (the one I cloned from) and push to my clone. The first thing I did was add the master repo as a remote:

$ git remote add cavneb https://github.com/cavneb/airbrake-grails.git

If I again run git remote show origin I see the same output, so obviously I need to do something else to indicate that the cavneb repo should be used for fetching, but I'm not sure what this is.

In case it's relevant, I've shown the contents of my .git/config below:

[core]
    repositoryformatversion = 0
    filemode = true
    logallrefupdates = true
[remote "origin"]
    url = https://github.com/domurtag/airbrake-grails.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[remote "cavneb"]
    url = https://github.com/cavneb/airbrake-grails.git
    fetch = +refs/heads/*:refs/remotes/cavneb/*
Daenyth
  • 35,856
  • 13
  • 85
  • 124
Dónal
  • 185,044
  • 174
  • 569
  • 824

4 Answers4

12

Straight Up Answer

The command you are looking for is:

git remote set-url origin https://github.com/cavneb/airbrake-grails.git
git remote set-url origin --push https://github.com/domurtag/airbrake-grails.git

HOWEVER

But I would strongly advice against doing that.

Even though I'm not totally sure, with the above behaviour, git would/could get confused a lot.

When done like above, git assumes that this is the same repo. So when you push, the result of the next fetch should change – which it obviously won’t.

Best Practice

The proper way to handle your situation is to add the master repo as an extra remote. Again, as another best practice, I would call this repo upstream.

And when you want to pull from that extra repo(upstream):

git fetch upstream
git merge upstream/master
Can
  • 4,516
  • 6
  • 28
  • 50
Chronial
  • 66,706
  • 14
  • 93
  • 99
  • I use `upstream` and `origin` for my minor forrays into supporting git itself, so I fetch from upstream, while push/pull from my personal `origin` on Github. Have a look in the git mailing list for recent discussions on triangle workflows. – Philip Oakley Apr 09 '13 at 15:26
  • ? is that not exactly the same as what I explained? – Chronial Apr 09 '13 at 15:43
  • It was the mixture of the two aspects that probably made me write the comment. Perhaps if the answer had started with your "The proper way .." para, and only after gave the command being looked for and the 'don't do that' sentiment. I suppose it depends on writing style though. Sorry for any offence. – Philip Oakley Apr 10 '13 at 12:04
  • No offense taken – I was just confused :) – Chronial Apr 10 '13 at 13:38
4

Git 1.8.3 introduces settings that help with triangular workflows.

remote.pushdefault: the remote to push changes to. Can be overriden on a specific branch by setting branch.<branch>.pushremote.

With either setting, git push (with no further arguments) will push to your preferred remote, and not the branch's upstream remote. See the 1.8.3-rc2 announcement for details.

Tobu
  • 24,771
  • 4
  • 91
  • 98
1

Unless i'm mistaken, there is no such thing as a --pull option for git remote set-url : https://git-scm.com/docs/git-remote#git-remote-emset-urlem

Arkhena
  • 270
  • 2
  • 10
0

Try using the set-url with pull and push:

git remote set-url --pull origin https://github.com/domurtag/airbrake-grails.git
git remote set-url --push origin https://github.com/cavneb/airbrake-grails.git
bubba
  • 3,839
  • 21
  • 25