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 [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?

6
  • 1
    git push origin http://second.... Commented Jul 15, 2017 at 7:37
  • 1
    Are you sure both remotes are named origin? Is that even allowed? Commented Jul 15, 2017 at 7:41
  • @Julian yes I tested it before, and I pasted my terminal export of command git remote -v Commented Jul 15, 2017 at 7:42
  • Name the second remote a different name as origin2 or any other than origin. Commented Jul 15, 2017 at 8:31
  • @RamKumar I did, but what happened if I want to run command git pull? does it fetch from both remotes? Commented Jul 15, 2017 at 8:35

2 Answers 2

1

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> 
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.