如何从局域网内的其他电脑在 windows 中 git 克隆一个 repo?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5200181/
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 to git clone a repo in windows from other pc within the LAN?
提问by Kou
I have this git repo "c:/xampp/htdocs/**" in my main PC and its IP address is 192.168.0.6. Now I want to git clone this repo from ubuntu-server which running on a Vmware Player in my main PC.
我的主 PC 中有这个 git repo "c:/xampp/htdocs/ **",它的 IP 地址是 192.168.0.6。现在我想从 ubuntu-server git clone 这个 repo,它在我的主 PC 上的 Vmware Player 上运行。
I did
我做了
git clone \192.168.0.6\c:\xampp\htdocs\****
and
和
git clone //192.168.0.6/c:/xampp/htdocs/****
from ubuntu-server and neither worked.
来自 ubuntu-server 并且都没有工作。
fatal: could not create work tree dir '****'.: Permission denied
What did I wrong? what should I do?
我做错了什么?我该怎么办?
采纳答案by eckes
To access the repo, you must either share it on 192.168.0.6
or must be the same domain user as the one that owns the file on 192.168.0.6
.
要访问存储库,您必须在 上共享它,192.168.0.6
或者必须与拥有文件的域用户相同192.168.0.6
。
If you share the directory on 192.168.0.6
(e.g. with share name myrepo
), you access it with //192.168.0.6/myrepo
.
如果您共享目录192.168.0.6
(例如使用共享名称myrepo
),您可以使用//192.168.0.6/myrepo
.
If you are logged in on your box with a user accout that is known on 192.168.0.6
, you could try accessing the repo through the administrative shares:
如果您使用已知的用户帐户登录您的盒子192.168.0.6
,您可以尝试通过管理共享访问存储库:
//192.168.0.6/c$/xampp/htdocs/...
Always use forward slashes.
始终使用正斜杠。
Another alternative would be using SSH to access the remote machine.
另一种选择是使用 SSH 访问远程机器。
回答by Roberto
You should use the command git daemon
to host your repo, like this:
您应该使用该命令git daemon
来托管您的存储库,如下所示:
In your computer that will act as a server:
在您将用作服务器的计算机中:
git daemon --base-path=<path_to_folder_containing_project_folder> --export-all
git daemon --base-path=<path_to_folder_containing_project_folder> --export-all
(please note that path_to_folder_containing_project
is the folder containing your projects folders, it will provide all projects under that folder)
(请注意,这path_to_folder_containing_project
是包含您的项目文件夹的文件夹,它将提供该文件夹下的所有项目)
In your client:
在您的客户端:
git clone git://<local ip>/<project name>
git clone git://<local ip>/<project name>
The cloned repo will have its origin pointing to the server in your LAN, so you may want to use git remote set-url origin
to point it to the original origin.
克隆的 repo 的源将指向 LAN 中的服务器,因此您可能希望使用git remote set-url origin
它指向原始源。
You may want to run git daemon
with the --verbose
option to get more details in case you run into problems.
如果遇到问题git daemon
,您可能希望使用该--verbose
选项来获取更多详细信息。
回答by ralphtheninja
Make sure that your c:/xampp/htdocs folder (or sub folders of it) is shared in windows, so you can navigate on the network by this address:
确保您的 c:/xampp/htdocs 文件夹(或其子文件夹)在 Windows 中共享,以便您可以通过以下地址在网络上导航:
\192.168.0.6\htdocs
Then you clone by using file:////. Note that there are fourslashes:
然后使用 file://// 进行克隆。请注意,有四个斜杠:
git clone file:////192.168.0.6/htdocs/somerepo.git
回答by Bulki S Maslom
To make git repo on Windows local network you'd need to do the following:
要在 Windows 本地网络上制作 git repo,您需要执行以下操作:
Create new repo
git init --bare projectName.git
Share this folder (projectName.git) with the users you need
- Find your PC ip with ipconfig command (e.g. 192.168.2.101)
Run this command from some user's machine
git clone //192.168.2.101/projectName.git
创建新仓库
git init --bare projectName.git
与您需要的用户共享此文件夹 (projectName.git)
- 使用 ipconfig 命令查找您的 PC ip(例如 192.168.2.101)
从某些用户的机器运行此命令
git clone //192.168.2.101/projectName.git
Note: open \\192.168.2.101 in finder to see the correct path to the projectName.git (e.g. //192.168.2.101/some/path/projectName.git)
注意:在finder中打开\\192.168.2.101查看projectName.git的正确路径(例如//192.168.2.101/some/path/projectName.git)
回答by Johannes Rudolph
Using explorer (smb) to mount the remote repository as a network share is the easiest way. I'm not entirely sure, but I think you paths might be wrong. Try file:///192.168.0.6\c:\xampp...
instead.
使用资源管理器 (smb) 将远程存储库挂载为网络共享是最简单的方法。我不完全确定,但我认为您的路径可能是错误的。试试吧file:///192.168.0.6\c:\xampp...
。
There are two things that might have gone wrong for you:
有两件事可能对你来说是错误的:
- You don't have read permission on the remote repository
- You don't have write permission in the location you want to create your repository ( the current working directory or the directory you specify as second argument to git clone)
- 您没有远程存储库的读取权限
- 您在要创建存储库的位置(当前工作目录或您指定为 git clone 的第二个参数的目录)没有写权限
And also check if your samba server works for normal file access.
还要检查您的 samba 服务器是否可以正常访问文件。
回答by AnonymousEngineer
I recently ran into this error while trying to clone a repository in a remote pc to a local pc within the same LAN network. The solution was to first make sure the drive location in the remote pc had the correct access rights for the local PC(Read/Write-which can be set using windows sharing options) Copy the path of the remote repository. In your local pc paste the path in a windows explorer window. Then copy its directory address and paste it into any browser. Now you should get a link with the hostname and the correct cloning URL format. Use this link to clone the repository in the local pc.
我最近在尝试将远程 pc 中的存储库克隆到同一 LAN 网络中的本地 pc 时遇到了这个错误。解决方案是首先确保远程PC中的驱动器位置对本地PC具有正确的访问权限(读/写-可以使用Windows共享选项设置)复制远程存储库的路径。在您的本地 PC 中,将路径粘贴到 Windows 资源管理器窗口中。然后复制其目录地址并将其粘贴到任何浏览器中。现在您应该得到一个包含主机名和正确克隆 URL 格式的链接。使用此链接在本地 pc 中克隆存储库。
Hope this helps. Cheers.
希望这可以帮助。干杯。
回答by Rayan Elmakki
"I have a few different computersthat I use at home and I wanted to set up GIT that I can access my code from any of them. It took me a bit because I was too used to working with a client-server model where I designate one machine as the "server" that holds the repository and everything else was a client. Instead, GIT seems to operate more like a merge tool and every local copy is its own "master." Once I understood that, it turns out that setting up GIT is very simple and just needs GIT itself and SSH".
“我在家里使用了几台不同的计算机,我想设置 GIT,以便我可以从其中任何一台计算机访问我的代码。这花了我一点时间,因为我太习惯于使用客户端 - 服务器模型指定一台机器作为保存存储库的“服务器”,其他所有东西都是客户端。相反,GIT 似乎更像是一个合并工具,每个本地副本都是它自己的“主”。一旦我明白了这一点,事实证明设置 GIT 非常简单,只需要 GIT 本身和 SSH”。
To read more you can check this link: http://blog.lazyhacker.com/2010/04/setting-up-git-for-home-network.html
要了解更多信息,您可以查看此链接:http: //blog.lazyhacker.com/2010/04/setting-up-git-for-home-network.html