如何使我的本地存储库可用于 git-pull?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/978052/
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 make my local repository available for git-pull?
提问by alastairs
I have a working copy repository that I've been working in no problem; the origin for this repository is on GitHub.
我有一个工作副本存储库,我一直在使用它没有问题;此存储库的来源在 GitHub 上。
I'd like to make my working copy repository available as the origin for my build machine (a VM on another physical host), so that commits I make to my working copy can be built and tested on the build machine without having to go via GitHub first. I already have a build for the GitHub repository going, but I'd like this to be a "golden" repository/build; i.e., if something goes in there, the build against GitHub should be guaranteed to pass.
我想让我的工作副本存储库可用作我的构建机器(另一台物理主机上的虚拟机)的源,以便我对工作副本所做的提交可以在构建机器上构建和测试,而无需通过先上GitHub。我已经为 GitHub 存储库进行了构建,但我希望这是一个“黄金”存储库/构建;也就是说,如果有东西进去,针对 GitHub 的构建应该保证通过。
I've looked at the documentation on Git URLs, and see that there's the option of using a URL in the form git://host.xz[:port]/path/to/repo.git/
(see, e.g., git-clone documentation). I want to do this in the simplest possible way, with the minimum of configuration: I don't want to have to set up an SSH daemon or web server just to publish this to my build machine.
我查看了有关 Git URL 的文档,发现可以选择在表单中使用 URL git://host.xz[:port]/path/to/repo.git/
(参见,例如git-clone 文档)。我想以最简单的方式做到这一点,使用最少的配置:我不想为了将其发布到我的构建机器而设置 SSH 守护程序或 Web 服务器。
I'm running Windows 7 x64 RC, I have MSysGit and TortoiseGit installed, and I have opened Git's default port (9814) on the firewall. Please assume working copy repo is at D:\Visual Studio Projects\MyGitRepo
, and the hostname is devbox
. The build machine is Windows Server 2008 x64. I have been trying the following command on the build machine, with the associated output:
我正在运行 Windows 7 x64 RC,我安装了 MSysGit 和 TortoiseGit,并且我在防火墙上打开了 Git 的默认端口 (9814)。请假设工作副本 repo 在D:\Visual Studio Projects\MyGitRepo
,主机名是devbox
。构建机器是 Windows Server 2008 x64。我一直在构建机器上尝试以下命令,以及相关的输出:
D:\Integration>git clone "git://devbox/D:\Visual Studio Projects\MyGitRepo"
Initialized empty Git repository in D:/Integration/MyGitRepo/.git/
devbox[0: 192.168.0.2]: errno=No error
fatal: unable to connect a socket (No error)
Am I missing something?
我错过了什么吗?
回答by Jakub Nar?bski
Five possibilities exist to set up a repository for pull from:
有五种可能性可以设置用于从以下位置拉取的存储库:
- local filesystem:
git clone /path/to/repo
orgit clone file://path/to/repo
. Least work if you have networked filesystem, but not very efficient use of network. (This is almost exactly solution proposed by Joakim Elofsson) - HTTP protocols:
git clone http://example.com/repo
. You need anyweb server, and you also need to run (perhaps automatically, from a hook) git-update-server-infoto generate information required for fetching/pulling via "dumb" protocols. - SSH:
git clone ssh://example.com/srv/git/repo
orgit clone example.com:/srv/git/repo
. You need to setup SSH server (SSH daemon), and have SSH installed on client (e.g. PuTTY on MS Windows). - git protocol:
git clone git://example.com/repo
. You need to run git-daemonon server; see documentation for details (you can run it as standalone process only for fetching, not necessary run as service). git-daemon is a part of git. - bundle: You generate bundle on server using git-bundlecommand, transfer it to a client machine in any way (even via USB), and clone using
git clone file.bndl
(if clone does not work, you can do "git init", "git remote add" and "git fetch").
- 本地文件系统:
git clone /path/to/repo
或git clone file://path/to/repo
. 如果您有网络文件系统,那么工作最少,但网络使用效率不高。(这几乎正是Joakim Elofsson提出的解决方案) - HTTP 协议:
git clone http://example.com/repo
。您需要任何Web 服务器,并且您还需要运行(可能自动,从钩子)git-update-server-info以生成通过“哑”协议获取/拉取所需的信息。 - SSH:
git clone ssh://example.com/srv/git/repo
或git clone example.com:/srv/git/repo
。您需要设置 SSH 服务器(SSH 守护进程),并在客户端(例如 MS Windows 上的 PuTTY)上安装 SSH。 - git协议:
git clone git://example.com/repo
。您需要在服务器上运行git-daemon;有关详细信息,请参阅文档(您可以将其作为独立进程运行,仅用于获取,而不需要作为服务运行)。git-daemon 是 git 的一部分。 - bundle:您使用git-bundle命令在服务器上生成包,以任何方式(甚至通过 USB)将其传输到客户端计算机,然后使用克隆
git clone file.bndl
(如果克隆不起作用,您可以执行“git init”、“git remote add” ”和“git fetch”)。
What you are missing in your example is probably running git-daemon on server. That, or misconfiguring git-daemon.
您在示例中缺少的可能是在服务器上运行 git-daemon。那,或者错误配置 git-daemon。
Unfortunately I cannot help you with running git-daemon as service on MS Windows. There is nothing in announcement for last version of msysGit about git-daemon not working, though.
不幸的是,我无法帮助您在 MS Windows 上将 git-daemon 作为服务运行。不过,关于 git-daemon 不工作的最新版本的 msysGit 公告中没有任何内容。
回答by Pod
In addition to Jakub Nar?bski's answers, there is anotherway, more in-line with your original question. You could clone from github like you usually do, then when you want to perform a one-off pull from your local repo, just do this:
除了 Jakub Nar?bski 的答案之外,还有另一种方式,更符合您的原始问题。您可以像往常一样从 github 克隆,然后当您想从本地存储库执行一次性拉取时,只需执行以下操作:
git pull /path/to/repo master
(instead of master you can put any branch name.)
(你可以输入任何分支名称,而不是 master。)
回答by Alec the Geek
The ssh route works well but does require a remote ssh server. If you have Windows platform then Cygwin provides a working ssh server that works with Git, but manually upgrade Git if using Cygwin Git (I wrote some hints at http://alecthegeek.wordpress.com/2009/01/21/top-tip-upgrade-git-on-cygwin/).
ssh 路由运行良好,但需要远程 ssh 服务器。如果你有 Windows 平台,那么 Cygwin 提供了一个可与 Git 一起使用的工作 ssh 服务器,但如果使用 Cygwin Git,则手动升级 Git(我在http://alecthegeek.wordpress.com/2009/01/21/top-tip 上写了一些提示-upgrade-git-on-cygwin/)。
回答by davenpcj
I recently changed one of my git projects to replicate itself to an HTTP server using sitecopy to do the actual file uploads.
我最近更改了我的一个 git 项目,使用 sitecopy 将其自身复制到 HTTP 服务器以执行实际的文件上传。
It's pretty easy, just use git update-server-info
then mirror the .git directory to some http-accessible directory on your server. I used 'project.git', which is fairly common.
这很简单,只需使用git update-server-info
然后将 .git 目录镜像到服务器上的某个 http 可访问目录即可。我使用了“project.git”,这很常见。
Git pull from http://site/project-gitworks like a champ, and I don't have to have anything on the server except FTP access, though sitecopy supports webdav as well.
Git pull from http://site/project-git像冠军一样工作,除了 FTP 访问之外,我不需要在服务器上有任何东西,尽管 sitecopy 也支持 webdav。
I don't recommend using sitecopy, however, as it doesn't keep multiple machines in sync well. For my project, the HTTP repository is readonly, and gold updates come from just one machine, so it works well enough.
但是,我不建议使用 sitecopy,因为它不能很好地保持多台机器的同步。对于我的项目,HTTP 存储库是只读的,并且黄金更新仅来自一台机器,因此它运行良好。
回答by metadings
If you have a path like
如果你有这样的路径
C:\Project\
and you did git init
already, so you also have a folder
你git init
已经做了,所以你还有一个文件夹
C:\Project\.git\
You now make a new folder
您现在创建一个新文件夹
C:\.git\
Go into that folder and run git clone --bare ..\Project
(bareis important),
go back to your C:\Project\
folder and do a git remote add-url local ..\.git\Project
.
Now you just do git add -A
, git commit -m "HelloWorld"
and git push local master
.
进入该文件夹并运行git clone --bare ..\Project
(bare很重要),
返回您的C:\Project\
文件夹并执行git remote add-url local ..\.git\Project
.
现在你只需要git add -A
,git commit -m "HelloWorld"
和git push local master
。
You may share the Project
folder, connect it to Z:
and do git clone Z:\Project
- you can use now git pull origin master
and git push origin master
to push/pull changes from one computer to another.
您可以共享Project
文件夹,将其连接到Z:
做git clone Z:\Project
-现在可以使用git pull origin master
,并git push origin master
以推/拉的变化从一台计算机到另一台。
回答by jnr
If your remote host is in the same windows network, i.e. you can access it as \remotehost, then you can map network drive in explorer, let's say z: --> \remotehost\repodir, after that you can use 'git clone /z/myproject' to clone project
如果你的远程主机在同一个windows网络中,即你可以以\remotehost的身份访问它,那么你可以在资源管理器中映射网络驱动器,比如说z:-->\remotehost\repodir,之后你可以使用'git clone / z/myproject' 来克隆项目