Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would be the opposite of "git fetch"?

Tags:

git

git-fetch

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?

like image 469
Rogach Avatar asked Mar 04 '13 11:03

Rogach


1 Answers

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/*
like image 52
CharlesB Avatar answered Oct 17 '22 06:10

CharlesB