2

my project has 2 remote git server to push.

it pushes to both of them but fetch from the first one as you can see below:

git remote -v
origin  git@gitlab.com:XXXXXX/XXXXXX.git (fetch)
origin  git@gitlab.com:XXXXXX/XXXXXX.git (push)
origin  http://second_server_ip:port/XXXXXX/XXXXXX.git (push)

some times the first one is going down for deploying new version or some other stuff and in these times if I want to push I will get this error:

git push
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

but the second server is up.

so is there any way to push just in the second server?

Seyed Ali Roshan
  • 1,476
  • 1
  • 18
  • 37

2 Answers2

1

Way 1 - Sequence

Make second repository push queue in front of first one:

git remote -v
origin  git@gitlab.com:XXXXXX/XXXXXX.git (fetch)
origin  http://second_server_ip:port/XXXXXX/XXXXXX.git (push)
origin  git@gitlab.com:XXXXXX/XXXXXX.git (push)

By doing this way you will first push to second server then get error from first server after the push has done.


Way 2 - Different Repository

Add or edit the second repository as a new local repository name likes:

git remote -v
origin  git@gitlab.com:XXXXXX/XXXXXX.git (fetch)
origin  git@gitlab.com:XXXXXX/XXXXXX.git (push)
origin  http://second_server_ip:port/XXXXXX/XXXXXX.git (push)
backup  http://second_server_ip:port/XXXXXX/XXXXXX.git (push)

When you want to push to only second server you could:

git push backup <branch>

To add a push url:

git remote set-url --add <name> <newurl>
Nick Tsai
  • 3,799
  • 33
  • 36
0

I have not tried it, but probably git -c remote.origin.url=http... push origin ... would do it

max630
  • 8,762
  • 3
  • 30
  • 55