12

If I do git fetch from repo A to B, the master branch in B doesn't change - changes only remotes/origin/master, and git status reminds me of it.

But now I want to do the opposite - update B from A, something like pushing from A:master to B:remotes/origin/master. The reason for this is that this update happens over ssh, and A machine has public-key auth to B machine - but not vice versa.

How can I do this?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Rogach
  • 26,050
  • 21
  • 93
  • 172
  • very related [“git push” doing the same as “git fetch” from the remote](http://stackoverflow.com/q/4239064/11343) – CharlesB Mar 04 '13 at 11:15

1 Answers1

10

git fetch A, run from B, will store all current branches of A in refs/remotes/A. As you can do pretty much everything with refspecs, it's possible to do the same for a git push, but run from A and targeting B.

A refspec has two parts, separated by a semicolon. In the first part you select what you want to push. Here you want all current branches, so this is refs/heads/*.

Second part is where you'll store them on the remote; here you want to store them under remotes/A/*, so this is refs/remotes/A/*.

Put it together, to push all local branches to corresponding remote branches with this command:

git push --force B refs/heads/*:refs/remotes/A/*
CharlesB
  • 86,532
  • 28
  • 194
  • 218