Seyed Ali Roshan
Seyed Ali Roshan

Reputation: 1574

git push : push to second remote

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  [email protected]:XXXXXX/XXXXXX.git (fetch)
origin  [email protected]: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?

Upvotes: 2

Views: 1902

Answers (2)

Nick Tsai
Nick Tsai

Reputation: 4129

Way 1 - Sequence

Make second repository push queue in front of first one:

git remote -v
origin  [email protected]:XXXXXX/XXXXXX.git (fetch)
origin  http://second_server_ip:port/XXXXXX/XXXXXX.git (push)
origin  [email protected]: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  [email protected]:XXXXXX/XXXXXX.git (fetch)
origin  [email protected]: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>

Upvotes: 1

max630
max630

Reputation: 9238

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

Upvotes: 0

Related Questions