我可能把这个复杂化了很多,但是我的机器上有一个 git repo,我还有另一台机器在工作,我通常会连接到工作。每隔一段时间,我需要将一些我主要在我的机器上开发的代码放到这台工作机器上,我只想使用 git 而不是使用 scp 或 rsync 复制代码,以便我可以跟踪版本等在。
所以要克隆 repo,我想我必须将 ssh 反向到工作机器,然后再次通过反向 ssh 连接克隆 git repo。
一个测试可能是
mkdir testgit && cd testgit
touch file
git init
git add file
git commit -m "test commit"
这在本地机器上。现在我正在尝试(但不起作用)是
localmachine $ ssh -R 43022:localhost:22 user@remote
remotemachine $ git clone ssh://user@localhost:43022/home/user/testgit/
然而Connection reset by peer
,这总是给我,所以我不认为我真的理解这种反向连接在做什么。这样做的正确方法是什么?
你不需要克隆到远程,尤其是这种过于复杂的方式,你只需要推送。
在远程端必须有 2 个存储库——裸和非裸。裸仓库是您从本地仓库推送的地方。非裸存储库是一个带有工作树(检出文件)的存储库,您可以从中提取。
创建一个新的空裸和非裸存储库;从本地推送到裸机:
ssh user@remote -p 43022 "
cd /home/user &&
git init --bare testgit.git &&
git init testgit &&
cd testgit &&
git remote add bare ../testgit.git"
git remote add work ssh://user@remote:43022/home/user/testgit.git
git push -u work master # or how do call your master branch
从裸拉到非裸:
ssh user@remote -p 43022 "cd /home/user/testgit && git pull bare master"
您可以使用裸仓库中的post-receive
或post-update
钩子自动执行最后一步。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句