如何在 Windows 上设置和克隆远程 git 存储库?

发布于 2025-01-06 12:32:23 字数 405 浏览 1 评论 0原文

有人知道如何从 Windows 服务器上的 git 远程存储库签出、克隆或获取项目或代码吗?

存储库 IP 为:xxx.xx.xxx.xx,源文件目录为 c:\repos\project.git

我习惯了 SUSE Linux 的命令行界面终端。我尝试过同样的方法,但它总是回复“

fatal: ''/repo/project.git'' does not appear to be a git repository
fatal: Could not read from remote repository..
Please make sure you have the correct access rights

谁能告诉我如何设置和克隆?”

Anybody know how to checkout, clone, or fetch project or code from a git remote repository on a Windows server?

Repository IP is: xxx.xx.xxx.xx, source file directory is c:\repos\project.git

I am used to the command line interface from a SUSE Linux terminal. I have tried the same kind of method but it always replies that

fatal: ''/repo/project.git'' does not appear to be a git repository
fatal: Could not read from remote repository..
Please make sure you have the correct access rights

Can anyone tell me how to setup and clone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回忆凄美了谁 2025-01-13 12:32:23

您必须从 Windows 计算机设置某种共享,您可以使用 git 访问该共享。 Git 支持 3 种访问方法:ssh、远程文件系统或 http。最后一项可能是最复杂的,所以我不会详细说明。前两个是:

  1. 在 Windows 上设置 ssh 服务器。

    您可以尝试本指南:http://www.timdavis.com.au/git/setting-up-a-msysgit-server-with-copssh-on-windows/ 另请参阅此问题了解更多选项

    更新 2o23: Microsoft 如今实际上为 Windows 提供了 OpenSSH,其中包括一项您可以立即开始获取 ssh 服务器的服务。 官方指南从这里开始。它的版本有点旧,但这仅适用于将 SSH 代理暴露给 WSL2 和/或 VM。

    比你通过 git clone [email protected] 克隆:/c/git/path/to/repo (系统会要求您提供密码)。

    这种方法的优点是它是安全的(连接是加密的并且 ssh 服务器是值得信赖的),因此您可以通过互联网使用它。由于访问时git服务器运行在windows机器上,因此您可以设置高级安全策略的钩子,控制其他进程等。

  2. 使用 Windows 共享来共享存储库。

    与在Linux主机上相比,您需要使用smbmount挂载共享。这可能需要用户名和密码,具体取决于您设置权限的方式。

    比你通过git clone /share/mountpoint/path/to/repo克隆。

    这可能更容易设置,但不是很安全,因此不应该在本地网络之外使用。同样在这种情况下,Windows 机器上的钩子将不会被执行(事实上 git 会尝试在 Linux 机器上执行它们,但它们要么不会在那里运行,要么无论如何都可以被绕过),所以你不能应用高级安全。

特定文件不相关,您需要提供包含 .git 子目录的目录或裸存储库目录的路径(上面的 path/to/repo ) 。

You have to set up some kind of sharing from the windows machine, that you can access with git. Git supports 3 access methods: ssh, remote filesystem or http. The last one is probably most complicated, so I won't detail it. The first two are:

  1. Set up ssh server on windows.

    You can try this guide: http://www.timdavis.com.au/git/setting-up-a-msysgit-server-with-copssh-on-windows/. See also this question for some more options

    Update 2o23: Microsoft actually offers OpenSSH for Windows these days, including a service that you can just start to get a ssh server. Official guide starts here. It's a bit older version, but that only matters for exposing SSH agent to WSL2 and/or VMs.

    Than you clone by git clone [email protected]:/c/git/path/to/repo (you will be asked for password).

    Advantage of this method is that it's secure (connection is encrypted and ssh server is trustworthy), so you can use it over internet. Since git server is running on the windows machine during access, you can set up hooks for advanced security policy, controlling other processes and such.

  2. Share the repository using windows sharing.

    Than on the linux host, you need to mount the share with smbmount. That might require username and password, depending on how you set the permissions.

    Than you clone by git clone /share/mountpoint/path/to/repo.

    This is probably easier to set up, but it is not very secure, so it shouldn't be used outside local network. Also in this case hooks on the windows machine won't be executed (in fact git will try to execute them on the Linux machine, but they either won't run there or can be bypassed anyway), so you can't apply advanced security.

A particular file is not relevant, you need to give path to the directory containing .git subdirectory or to the directory that is a bare repository (path/to/repo above).

神也荒唐 2025-01-13 12:32:23

首先,git 存储库只是您需要访问的一堆文件。您写了有关克隆和获取存储库的文章,这是简单的部分 - 您只需要访问文件(并具有读取权限)。

它可以通过直接访问文件系统、通过 http(s) 协议或通过 ssh 连接来完成。实际上,甚至还有一种方法可以通过 ftp 服务器来完成。

你可以做什么:

1)设置ssh服务器,然后通过ssh服务器访问git文件 - 实际上,你应该使用的路径取决于你在Windows上使用的ssh服务器: 来源

2)设置Web服务器访问文件:
git clone http://host/path/to/repo

3) 在 Linux 机器上从 Windows 挂载文件系统并克隆存储库:
git clone /mnt/filesystem/path/to/repo

尽管您选择了这种方法,我建议您查阅 Pro Git 书籍

First of all, the git repository is just a bunch of files you need to access. You wrote about cloning and fetching repository, and this is easy part - you just need to access the files (and have read rights).

It can be done by direct access to filesystem, by http(s) protocol, or by ssh connection. Actually, there is even a way to do it by ftp server.

What you can do:

1) set the ssh server, then access the git files via ssh server - actually, the path you should use depends on the ssh server you use on windows: source

2) set the web server to access the file:
git clone http://host/path/to/repo

3) mount filesystem from windows on your linux machine and clone repo:
git clone /mnt/filesystem/path/to/repo

Despite the method you choose I suggest to consult the apropriate chapter from Pro Git Book

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文