2

This is my scenario, I have two servers and my PC:

The origin project is on Remote Server A with git, I clone into my PC, I can edit this project and push to Remote Server A.

But now there is another requirement, that is I want to publish my project to Remote Server B in a directory such as /www/wwwroot/.

enter image description here

What should I do? how to set the git environment in Remote Server B/PC then I can use PC to push code to Remote Server B? Because in this case I can not clone from PC to Remote Server B, because the PC is a NAT address.

user7693832
  • 6,119
  • 19
  • 63
  • 114

2 Answers2

2

To understand which origin have you configured for pushing to "Server A" do a git remote get-url origin.

Then check which can be the address of the "Server B" new origin and add it as a new origin like: git remote add serverb https://serverb.com/gitrepo.git.

Then whenever you would like to push to serverb do a git push serverb <branch-name>

denis_lor
  • 6,212
  • 4
  • 31
  • 55
  • Before this, you would first need to create `gitrepo` in server B and run `git init`. – GoodDeeds Nov 15 '19 at 14:50
  • That's a great addition in case he has the permission to create a git repo over there or just to push things to an existing repo without the possibility to clone/init a git repo. But for sure in case he has that kind of permission, he would need that step too. – denis_lor Nov 15 '19 at 22:50
0

In this scenario

1.in server B /www/wwwroot:

#git init project_name
#cd project_name
#git config receive.denyCurrentBranch ignore

2.in PC push to serverB

#git remote add remote_14.193.1.1 root@14.193.1.1:/www/wwwroot/project_name/.git
#git push remote_14.193.1.1

3.in server B

#git reset --hard
aircraft
  • 25,146
  • 28
  • 91
  • 166