I have a Git repository with a single origin
remote, and that remote has two pushurls, one for each of the servers foo
and bar
:
$ git remote set-url --add --push origin me@foo:path/to/repo.git
$ git remote set-url --add --push origin me@bar:path/to/repo.git
The intent here was to always have an upstream mirror bar
in case I (temporarily) lose access to the main server foo
. With this configuration, I can issue a simple git push
and have my commits automatically propagated to both servers. Until now I have found this solution to be more convenient than setting up multiple remotes, since the latter requires issuing separate git push
commands for each remote (or creating a shell script/alias that does this automatically and then remembering to install it on all my machines).
The problem with the multiple-pushurls approach is that when the main server really does go down or otherwise becomes temporarily inaccessible, git push
aborts before even attempting to push to the mirror server:
$ git push -v
Pushing to me@foo:path/to/repo.git
GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
$
How can I make git push
ignore such errors and instead move on to the next pushurl in the list?