Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用git同步两个相同的repo,一个在本地,另一个在远程主机(不是github)_Git - Fatal编程技术网

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

使用git同步两个相同的repo,一个在本地,另一个在远程主机(不是github),git,Git,我在本地主机和远程主机上安装了git,并且安装了相同的项目文件夹因此本地主机上的1个repo和远程主机上的1个repo都包含相同的文件。我想做的是使用localhost文件进行开发,然后将它们推送到远程服务器进行更新 如何操作?只需在本地repo中添加一个远程,然后推送到远程主机 git remote add origin /url/remotehost/bare_repo git push --all 为此,您的远程主机必须能够通过以下方式之一被本地主机访问: git守护进程 共享文件夹

我在本地主机和远程主机上安装了git,并且安装了相同的项目文件夹
因此本地主机上的1个repo和远程主机上的1个repo都包含相同的文件。我想做的是使用localhost文件进行开发,然后将它们推送到远程服务器进行更新


如何操作?

只需在本地repo中添加一个远程,然后推送到远程主机

git remote add origin /url/remotehost/bare_repo
git push --all
为此,您的远程主机必须能够通过以下方式之一被本地主机访问:

  • git守护进程
  • 共享文件夹
  • http(s)
  • ssh
您的远程主机必须有一个,才能推送到它

在裸回购协议上,你可以宣布


OP选择了ssh(
ssh://202.XXX.xx.xx:/path/to/repo.git
),但在获取/推送时出现问题

克隆远程回购协议也不起作用,因为它给出了一个错误

我建议指定在远程服务器上拥有repo的用户。
例如“
git
”:
git@202.XXX.xx.xx

然后尝试使用和不使用“
”:

git@202.XXX.xx.xx:/path/to/repo.git 
# or 
git@202.XXX.xx.xx/path/to/repo.git
sshd必须运行。端口应为默认端口(22)。
你可以检查一下

在所有这些之后,Op报告设置正在工作


post receive
钩子必须放在服务器上的裸repo中,并使其可执行:

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