eamon316
eamon316

Reputation: 101

Sync Git Repository on 2 remotes

I have Network A and Network B.
Stash runs on A and Gitlab runs on B but they cannot communicate across networks.

1 group of developers actively work on A and the other group of developers actively work on B. I have a machine that can see both.

So, daily I would like to be able to pull all updates, branches and tags from A and push to B, in reverse I would like to pull all updates, branches and tags from B and push to A.

I have cloned from A and added an additionl remote git remote add networkb git@<ip-address>:group/project.git

So now I have git remote -v:

networkb git@<networkb-ip-address>:group/project.git (fetch)
networkb git@<networkb-ip-address>:group/project.git (push)
origin git@<networka-ip-address>:group/project.git (fetch)
origin git@<networka-ip-address>:group/project.git (push)
  1. git push networkb --all only works for locally checked out branches.
  2. git push networkb '*:*' pushed everything to B but I cannot see branches when checkout from
  3. git push networkb +refs/remtes/origin/*:refs/heads/* worked for initial push but will result in a force push if run again.

Could anyone provide a sequence of steps to keeping these 2 remote repositories in sync?

Upvotes: 2

Views: 76

Answers (1)

LeGEC
LeGEC

Reputation: 51850

Inside your intermediate repository, you can the list of branch on origin using :

git for-each-ref --format="%(refname:short)" refs/remotes/origin

(change origin to networkb to get branches on networkb).


You can iterate through this list to either blindly push to networkb,
or try to first run a merge to see if any conflicts will happen,
or create networka/branches on networkb and and networkb/branches on networka.

Upvotes: 1

Related Questions