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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9308952/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:36:36  来源:igfitidea点击:

How to setup and clone a remote git repo on Windows?

linuxwindowsgitssh

提问by user1213492

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

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

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

仓库IP是:xxx.xx.xxx.xx,源文件目录是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

我习惯了 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

Can anyone tell me how to setup and clone?

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

回答by Jan Hudec

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:

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

  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 questionfor some more options.

    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.

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

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

    比你克隆git clone [email protected]:/c/git/path/to/repo(你会被要求输入密码)。

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

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

    比在 linux 主机上,您需要使用smbmount. 这可能需要用户名和密码,具体取决于您设置权限的方式。

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

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

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

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

回答by Micha? Zabielski

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).

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

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.

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

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

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

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

2)设置web服务器访问文件: 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

3)在你的linux机器上从windows挂载文件系统并克隆repo: git clone /mnt/filesystem/path/to/repo

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

尽管您选择了这种方法,但我建议您查阅Pro Git Book 中的相应章节