I want to have multiple remote servers which should mirror each other for all branches.
Starting this adventure, I found: pull/push from multiple remote locations
which tells me:
$ git remote set-url origin --push --add <a remote>
$ git remote set-url origin --push --add <another remote>
If I do a
$ git pull --all
Fetching origin
Fetching willi
Looks good!
But pushing did not work:
$ git push --all
To ssh://gitmini@localhost/home/gitmini/gitrepos/repo1
f974ce2..c146f0a master -> master
No push to my second remote! Why?
So if I try a different approach like:
$ git remote add mirroring ssh://gitmini@localhost/home/gitmini/gitrepos/repo2
$ git remote set-url mirroring --push --add ssh://gitmini@localhost/home/gitmini/gitrepos/repo1
$ git remote -vv
mirroring ssh://gitmini@localhost/home/gitmini/gitrepos/repo2 (fetch)
mirroring ssh://gitmini@localhost/home/gitmini/gitrepos/repo1 (push)
Which is really not what I expect!
There is an additional option --mirror=fetch|pull
but this also results in misconfigured results.
As mentioned in some comments, it is possible to add a url if a command is repeated. But I can never add more than one repo for fetching. As example I can go to this result, which to me seems buggy at best:
$ git remote -vv
mirroring ssh://gitmini@localhost/home/gitmini/gitrepos/repo1 (fetch)
mirroring ssh://gitmini@localhost/home/gitmini/gitrepos/repo2 (push)
mirroring ssh://gitmini@localhost/home/gitmini/gitrepos/repo1 (push)
mirroring ssh://gitmini@localhost/home/gitmini/gitrepos/repo2 (push)
As a next try I run:
$ git config -e
and added the following section:
[remote "mirroring"]
url = ssh://gitmini@localhost/home/gitmini/gitrepos/repo1
fetch = +refs/heads/*:refs/remotes/mirroring/*
pushurl = ssh://gitmini@localhost/home/gitmini/gitrepos/repo1
url = ssh://gitmini@localhost/home/gitmini/gitrepos/repo2
fetch = +refs/heads/*:refs/remotes/mirroring/*
pushurl = ssh://gitmini@localhost/home/gitmini/gitrepos/repo2
But
$ git remote -vv
mirroring ssh://gitmini@localhost/home/gitmini/gitrepos/repo1 (fetch)
mirroring ssh://gitmini@localhost/home/gitmini/gitrepos/repo1 (push)
mirroring ssh://gitmini@localhost/home/gitmini/gitrepos/repo2 (push)
the line for fetch of repo2
is simply ignored!
In fact, I am not able to set up the configuration. My task is simple: Have two remotes in sync.
EDIT: Some comments on the given answer from torek:
It looks that it is possible to set:
[remote "mirroring"]
url = ssh://gitmini@localhost/home/gitmini/gitrepos/repo1
fetch = +refs/heads/*:refs/remotes/mirroring/*
pushurl = ssh://gitmini@localhost/home/gitmini/gitrepos/repo1
url = ssh://gitmini@localhost/home/gitmini/gitrepos/repo2
fetch = +refs/heads/*:refs/remotes/mirroring/*
pushurl = ssh://gitmini@localhost/home/gitmini/gitrepos/repo2
With this configuration a
$ git push mirroring
...
To ssh://gitmini@localhost/home/gitmini/gitrepos/repo1
...
To ssh://gitmini@localhost/home/gitmini/gitrepos/repo2
results in pushing to both remotes.
I have no idea if this configuration is valid or not.
Torek writes:
If you configure more than one, only one of them works, all the others are ignored.
seems not to be true. In my given configuration all remotes will be accessed by push and pull as given my example above.
In fact the group as configured with [remotes]
looks very useful for my use case!