如何从另一台机器“git clone”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2808177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I 'git clone' from another machine?
提问by hap497
On one machine (IP address 192.168.1.2), I create a Git repository by
在一台机器(IP 地址 192.168.1.2)上,我创建了一个 Git 存储库
$ cd /home/hap/working
$ git init
$ (add some files)
$ git add .
$ git commit -m 'Initial commit'
And I have another machine on the same Wi-Fi network. How can I get clone from the other machine?
我在同一个 Wi-Fi 网络上有另一台机器。我怎样才能从另一台机器上克隆?
回答by Josiah
You need to use a git+ssh URLto perform the Git cloning:
您需要使用 git+ssh URL来执行 Git 克隆:
git clone git+ssh://[email protected]/~/working
To break it down:
分解:
git+ssh
tells Git that you want to use ssh to connect to the Git repository.hap
is your username (I assume based on the home directory in your question).192.168.1.2
is the machine that you want to connect to~/working
is the path to your Git repository on the remote machine (so~
is your home directory)
git+ssh
告诉 Git 您要使用 ssh 连接到 Git 存储库。hap
是您的用户名(我假设基于您问题中的主目录)。192.168.1.2
是您要连接的机器~/working
是远程计算机上 Git 存储库的路径(~
您的主目录也是如此)
Some other things to note:
其他一些注意事项:
- You need to have a ssh server enabled on the machine with the Git repository
- You'll need to know the password for the user
hap
- 您需要在带有 Git 存储库的机器上启用 ssh 服务器
- 您需要知道用户的密码
hap
回答by Jakub Nar?bski
I assume that on both machines you have installed Git.
我假设您在两台机器上都安装了 Git。
Now what you do depends on what services you have installed, that is, how you can connect from one machine to the other.
现在您做什么取决于您安装了哪些服务,即如何从一台机器连接到另一台机器。
The simplest case is when you have sshd
running on the machine you want to clone from, and you can ssh from the machine you want to clone toto the machine you want to clone from.
最简单的情况是,当你sshd
要克隆的机器上运行的,你可以ssh从要克隆机器到你想从克隆机。
If you can do
如果你能做到
ssh 192.168.1.2
(or if you have different username on the other machine, ssh [email protected]
), then you should be able to clone via SSH, like Josiah wrote:
(或者,如果您在另一台机器上有不同的用户名,ssh [email protected]
),那么您应该能够通过 SSH 进行克隆,就像Josiah 写道:
git clone git+ssh://[email protected]/~/working
If you want to continue to fetch / push between machines, you should configure public key authentication for SSH, to not have to provide password on each fetch.
如果你想继续在机器之间获取/推送,你应该为 SSH 配置公钥认证,不必在每次获取时都提供密码。
If you don't have sshd installed on the source machine, you can clone using "smart" HTTP protocol if you have a web server installed and can install CGI scripts (see git-http-backendmanpage), or you can clone using "dumb" HTTP protocol if you have web server installed, but can only serve static files (you would need to run git update-server-info
in source repository first), or you can clone using rsyncif you have it installed.
如果您没有在源计算机上安装 sshd,如果您安装了 Web 服务器并且可以安装 CGI 脚本,则可以使用“智能”HTTP 协议进行克隆(请参阅git-http-backend联机帮助页),或者您可以使用“进行克隆”如果您安装了 Web 服务器,则使用“愚蠢”HTTP 协议,但只能提供静态文件(您需要先git update-server-info
在源存储库中运行),或者如果安装了rsync,则可以使用它进行克隆。
As a last resort, you can use "git bundle" to create an archive which you can move, for example, using a USB pendrive and clone from it.
作为最后的手段,您可以使用“ git bundle”创建一个可以移动的存档,例如,使用 USB 随身碟并从中克隆。
回答by Michiel
I think people are looking for this answer. The following command in the terminal wil login into the other computer and clone an existing repo. In the current path location of the terminal (so cd
to the preferred location first).
我认为人们正在寻找这个答案。终端中的以下命令将登录到另一台计算机并克隆现有的存储库。在终端的当前路径位置(所以cd
先到首选位置)。
git clone [email protected]:/home/path/to/repo.git
In case you do not now the IP address. Use ping to determine the ip of your server. After the IP address don't forget to use the use a :
and then write the absolute path.
如果您现在没有 IP 地址。使用 ping 来确定您的服务器的 ip。后面的IP地址不要忘记用use a:
然后写绝对路径。