我如何使我的本地存储库可用于 git-pull?

我有一个可用的副本存储库,这个存储库是在 GitHub 上建立的。

我想让我的工作副本存储库作为构建机器(另一个物理主机上的 VM)的原点,这样我对工作副本的提交就可以在构建机器上构建和测试,而不必首先通过 GitHub。我已经为 GitHub 存储库构建了一个版本,但我希望这是一个“黄金”存储库/构建; 也就是说,如果有什么东西在那里,针对 GitHub 的构建应该保证通过。

我查看了关于 Git URL 的文档,发现可以选择使用形式为 git://host.xz[:port]/path/to/repo.git/的 URL (参见,例如,Git 克隆文档)。我想用尽可能简单的方式来完成这项工作,同时尽可能减少配置: 我不想仅仅为了将它发布到我的构建机器上就必须设置一个 SSH 守护进程或 Web 服务器。

我正在运行 Windows 7 x64 RC,我已经安装了 MSysGit 和 TortoiseGit,并且我已经在防火墙上打开了 Git 的默认端口(9814)。请假设工作副本回收是在 D:\Visual Studio Projects\MyGitRepo,并且主机名是 devbox。构建计算机是 WindowsServer2008x64。我一直在生成机器上尝试以下命令,以及相关的输出:

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)

我错过了什么吗?

82073 次浏览

Five possibilities exist to set up a repository for pull from:

  • local filesystem: git clone /path/to/repo or git 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 any web server, and you also need to run (perhaps automatically, from a hook) git-update-server-info to generate information required for fetching/pulling via "dumb" protocols.
  • SSH: git clone ssh://example.com/srv/git/repo or git 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-daemon on 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-bundle command, 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").

What you are missing in your example is probably running git-daemon on server. That, or misconfiguring 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.

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:

git pull /path/to/repo master

(instead of master you can put any branch name.)

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

I recently changed one of my git projects to replicate itself to an HTTP server using sitecopy to do the actual file uploads.

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 pull from http://site/project-git works like a champ, and I don't have to have anything on the server except FTP access, though sitecopy supports webdav as well.

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.

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

If you have a path like

C:\Project\

and you did git init already, so you also have a folder

C:\Project\.git\

You now make a new folder

C:\.git\

Go into that folder and run git clone --bare ..\Project (bare is 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.

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.