使一个本地git repo克隆

时间:2014-07-10 23:04:30

标签: git git-clone

我有一个本地的git repo。现在,我无法在github上传代码,但代码位于具有公共IP的机器上。 那么,如果我想能够从不同的机器克隆存储库,我需要做什么。

感谢

3 个答案:

答案 0 :(得分:2)

如果代码位于远程服务器上,您可以使用git clone

git clone ssh://user@host/var/local/git/repo.git

如果代码是本地的,您可以在遥控器上创建一个裸git仓库并推送您的代码。您可以设置git以将远程服务器用作"远程"。然后你可以推/拉。

#on remote
cd /var/local/git
mkdir myrepo.git
cd myrepo.git
git init --bare

#on local
git remote add origin ssh://user@host/var/local/git/myrepo.git
git push -u origin master

在远程创建新的repo,然后使用git push将代码推送到远程服务器中,然后使用上面的{{1命令。

答案 1 :(得分:0)

我将假设这里的想法是让你将该机器用作遥控器。如果您只想将存储库从一台计算机移动到另一台计算机,只需使用sircapsalot's comment中提到的SCP。

幸运的是,这本书Pro Git有一章就是这个,设置了你自己的Git服务器..我不知道你想要使用哪种协议,或者设置是什么样的,所以我只是直接链接到章节:http://git-scm.com/book/en/Git-on-the-Server

答案 2 :(得分:0)

如果您使用来自同一网络/机器的 repo 进行代码检出。它应该看起来像这样。 (将 .git 添加到项目位置的末尾)

//local_ip/location/project/.git(同局域网)

D:/Location/ProjectDirectory/.git(同一台机器)

git clone "//local_ip/location/project/.git" should work.

同样适用于 Jenkins 构建作业。将 git url 替换为上述位置。