Git serve:我想要这么简单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/377213/
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
Git serve: I would like it that simple
提问by Setori
回答by seanhodges
Navigate into your project and start git-daemon with the following switches:
导航到您的项目并使用以下开关启动 git-daemon:
cd project
git daemon --reuseaddr --base-path=. --export-all --verbose
This tells git-daemon to serve up all projects inside the current directory (which I assume is the project directory containing the .git/ folder). It also tells it to re-use the same address if you shut it down and start it back up too fast.
这告诉 git-daemon 为当前目录中的所有项目提供服务(我假设它是包含 .git/ 文件夹的项目目录)。它还告诉它在您关闭它并快速启动它时重新使用相同的地址。
You can put this into a batch script with an easy to remember name like "gitserve", so you don't need to type it all out again. As suggested in some of the comments, in recent versions of Git you can add an alias to the Git config:
您可以将其放入一个批处理脚本中,并使用一个易于记忆的名称(如“gitserve”),这样您就无需再次将其全部输入。正如一些评论中所建议的,在最新版本的 Git 中,您可以向 Git 配置添加别名:
[alias]
serve = !git daemon --reuseaddr --verbose --base-path=. --export-all ./.git
Once that's done on the server (your Windows box), you can do:
在服务器(您的 Windows 机器)上完成此操作后,您可以执行以下操作:
git serve
git-daemon uses the git:// protocol for transport, so on the client (your Linux box), you would need to do:
git-daemon 使用 git:// 协议进行传输,因此在客户端(您的 Linux 机器)上,您需要执行以下操作:
git clone git://123.456.789.111/ project
回答by Otto
Rather than write your own batch script, use gitjour. It knows how to start git daemon correctly and will broadcast the clone URL via mDNS so you can do gitjour showon the linux box and copy and paste.
与其编写自己的批处理脚本,不如使用gitjour。它知道如何正确启动 git daemon 并将通过 mDNS 广播克隆 URL,因此您可以gitjour show在 linux 机器上进行复制和粘贴。
Also a good article with an overview of gitjour and a number of other similar tools from Dr. Nic, What is *jour and why they are killer apps for RailsCamp08.
也是一篇很好的文章,概述了 gitjour 和 Nic 博士的许多其他类似工具,什么是 *jour 以及为什么它们是 RailsCamp08 的杀手级应用程序。
回答by criskiev
Currently using two aliases - serve and hub. Serve for read-only share and hub for read/write share:
目前使用两个别名 - 服务和集线器。为只读共享服务,为读/写共享服务集线器:
[alias]
serve = !git daemon --base-path=. --export-all --reuseaddr --informative-errors --verbose
hub = !git daemon --base-path=. --export-all --enable=receive-pack --reuseaddr --informative-errors --verbose
Also, there is more detailed tutorial about sharing via git daemon: http://l.rw.rw/git-daemon.
此外,还有更详细的关于通过 git daemon 共享的教程:http: //l.rw.rw/git-daemon。
回答by John Mee
If you just want to expose the repository with a web browser
如果您只想使用 Web 浏览器公开存储库
$ git instaweb -d apache2 --start
$ lynx localhost:1234
回答by bara
Here is an alternative way. You will need python installed.
这是另一种方法。您将需要安装 python。
- run
git update-server-info - go to the
.gitdirectory - run
python -mSimpleHTTPServer
- 跑
git update-server-info - 进入
.git目录 - 跑
python -mSimpleHTTPServer
(just create an alias in your gitconfig)
(只需在您的 gitconfig 中创建一个别名)
Now you can pull the repo with git pull http://HOST_NAME:8000/
现在你可以用 git pull http://HOST_NAME:8000/
PS: when usingthe git daemon solution you can set --base-path=.gitso the url is git://HOST/
PS:当使用 git daemon 解决方案时,你可以设置--base-path=.git这样的 urlgit://HOST/
回答by alberthier
git-webui is a git extension which provides a web based user interface and the ability to clone/pull from other computers
git-webui 是一个 git 扩展,它提供基于 Web 的用户界面和从其他计算机克隆/拉取的能力
https://github.com/alberthier/git-webui
https://github.com/alberthier/git-webui
$ cd my_git_repo
$ git webui
Other people can
其他人可以
$ git clone http://<ip-of-your-computer>:8000/ repoclone
or
或者
$ git pull http://<ip-of-your-computer>:8000/
回答by Nayagam
Add following lines in .git/config
在 .git/config 中添加以下几行
[instaweb]
local = true
httpd = webrick
port = 4231
then execute
然后执行
git instaweb
回答by VonC
Git 2.21 (Feb. 2019) allows you to combine python and git instaweb:
Git 2.21(2019 年 2 月)允许您结合使用 python 和git instaweb:
See commit 2eb14bb(28 Jan 2019) by Arti Zirk (artizirk).
(Merged by Junio C Hamano -- gitster--in commit abf39e3, 05 Feb 2019)
请参阅Arti Zirk ( ) 的commit 2eb14bb(28 Jan 2019 )。(由Junio C Hamano合并-- --在2019 年 2 月 5 日提交 abf39e3 中)artizirkgitster
git-instaweb: add Python builtinhttp.serversupportWith this patch it is possible to launch
git-instawebby using Pythonhttp.serverCGI handler via-d pythonoption.
git-instawebgenerates a small wrapper around thehttp.server(inGIT_DIR/gitweb/) that address a limitation of the CGI handler where CGI scripts have to be in acgi-binsubdirectory and directory index can't be easily changed. To keep the implementation small,gitwebis running on url/cgi-bin/gitweb.cgiand an automatic redirection is done when opening/.The generated wrapper is compatible with both Python 2 and 3.
Python is by default installed on most modern Linux distributions which enables running
git instaweb -d pythonwithout needing anything else.
git-instaweb: 添加 Python 内置http.server支持使用此补丁,可以通过选项
git-instaweb使用 Pythonhttp.serverCGI 处理程序启动-d python。
git-instaweb在http.server(inGIT_DIR/gitweb/)周围生成一个小包装器,解决 CGI 处理程序的限制,其中 CGI 脚本必须位于cgi-bin子目录中,并且目录索引不能轻易更改。为了保持实现较小,gitweb在 url 上运行/cgi-bin/gitweb.cgi并在打开/.生成的包装器与 Python 2 和 3 兼容。
Python 默认安装在大多数现代 Linux 发行版上,
git instaweb -d python无需其他任何东西即可运行。

