简体   繁体   English

使用git同步两个相同的存储库,一个在本地,另一个在远程主机上(不是github)

[英]using git to sync two identical repos one on local and other on remote host(not github)

I have git installed on localhost as well as remote host with the same project folder. 我在本地主机以及具有相同项目文件夹的远程主机上安装了git。
So 1 repo on localhost and 1 on remote host both containing same files. 因此,本地主机上的1个仓库和远程主机上的1个仓库都包含相同的文件。 What I want to do is use localhost files for development and then push them in the remote to update there as well. 我想做的是使用localhost文件进行开发,然后将其推送到远程进行更新。

How to go about it ? 怎么做呢?

Simply add a remote to your local repo, and push to your remote host. 只需将远程添加到本地存储库,然后推送到远程主机即可。

git remote add origin /url/remotehost/bare_repo
git push --all

For that, your remote host must have a way to be accessed by your local host through one of the supported protocols : 为此,您的远程主机必须有一种方法可以由本地主机通过一种受支持的协议进行访问:

  • git daemon git守护进程
  • shared folder 共享文件夹
  • http(s) HTTP(S)
  • ssh SSH

And your remote host must have a bare repo , in order to be able to push to it. 您的远程主机必须具有裸仓库 ,才能推送到该仓库。

On that bare repo, you can declare a post-receive hook which will checkout the received content in your remote host project folder . 在该裸仓库上,您可以声明一个接收后钩子,该钩子将在远程主机项目文件夹中签出接收到的内容


The OP chose ssh ( ssh://202.XXX.xx.xx:/path/to/repo.git ), but had issue fetching/pushing. OP选择了ssh( ssh://202.XXX.xx.xx:/path/to/repo.git ),但是在获取/推送时出现问题。

cloning the remote repo is also not working its giving me error 克隆远程仓库也无法正常工作,给我错误

 Bad port '' fatal: Could not read from remote repository.

I advised to specify the user which owns the repo on the remote server. 我建议指定在远程服务器上拥有该存储库的用户。
For instance ' git ': git@202.XXX.xx.xx . 例如' git ': git@202.XXX.xx.xx
Then to try with and without the ' : ': 然后尝试使用和不使用' : ':

git@202.XXX.xx.xx:/path/to/repo.git 
# or 
git@202.XXX.xx.xx/path/to/repo.git

The sshd must be running. sshd必须正在运行。 The port should be the default one (22). 该端口应为默认端口(22)。
One can check the sshd logs on the server side ( /var/auth/log ) . 可以在服务器端( /var/auth/log检查sshd日志

After all that, the Op reports the setup is working. 毕竟,Op报告安装程序正在运行。


The post-receive hook must be put in the bare repo on the server, and be made executable: post-receive挂钩必须放在服务器上的裸仓库中,并使其可执行:

cat > /path/to/bare/repo.git/hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/path/to/live/folder GIT_DIR=/path/to/bare/repo.git git checkout -f


chmod +x /path/to/bare/repo.git/hooks/post-receive

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM