通过 http 的私有 git 存储库

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

Private git repository over http

githttp

提问by pistacchio

can you recommend any no-brainer solution for setting up a git repository accessible via http(s, has cleutus suggested)? I have my own http server and I'd like to use it to host some minor private project. At home I can ssh it, but at work firewalls keep me from doing so.

您能否推荐任何简单的解决方案来设置可通过 http 访问的 git 存储库(已建议 cleutus)?我有自己的 http 服务器,我想用它来托管一些小型的私人项目。在家里我可以 ssh 它,但在工作中防火墙阻止我这样做。

Is there any free way to set up a small private git repository I can push / fetch to via http so that I can share projects between home and work? Thanks in advance!

有没有免费的方法来设置一个小型的私有 git 存储库,我可以通过 http 推送/获取,以便我可以在家庭和工作之间共享项目?提前致谢!

回答by Steve Nay

Git supports this natively. You'll need an HTTP server, of course.

Git 本身就支持这一点。当然,您需要一个 HTTP 服务器。

Put your (bare) repository in a folder that can be accessed by your web server. In that directory, run the following commands:

将您的(裸)存储库放在您的 Web 服务器可以访问的文件夹中。在该目录中,运行以下命令:

$ git --bare update-server-info
$ mv hooks/post-update.sample hooks/post-update

The first command provides extra information so the web server knows what to do with the repository. The second command makes sure that the information gets updated any time someone pushes to the repository.

第一个命令提供额外信息,以便 Web 服务器知道如何处理存储库。第二个命令确保信息在有人推送到存储库时随时更新。

You can find that information here: http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#setting-up-a-public-repository

您可以在此处找到该信息:http: //www.kernel.org/pub/software/scm/git/docs/user-manual.html#setting-up-a-public-repository

回答by Eddie

webDAV is not required

不需要 webDAV

And what is more, DAV is significantly slower than the new "smart-http" support since git 1.6.6. The new method allows the entire pack to be transmitted at once, and not as individual files.

更重要的是,从 git 1.6.6 开始,DAV 比新的“smart-http”支持慢得多。新方法允许一次传输整个包,而不是作为单个文件传输。



You can also use gitweb to provide browsable URLs at the same location.

您还可以使用 gitweb 在同一位置提供可浏览的 URL。

Note: Because access is controlled by apache you can add any Auth requirements (htaccess or ldap, etc) to the setup for each repository.

注意:因为访问是由 apache 控制的,所以您可以将任何 Auth 要求(htaccess 或 ldap 等)添加到每个存储库的设置中。



Just make a new git_support.conf file, and include it in apache (add include statement in httpd.conf)

新建一个 git_support.conf 文件,并包含在 apache 中(在 httpd.conf 中添加 include 语句)

#
#  Basic setup for git-http-backend
#

SetEnv GIT_PROJECT_ROOT /opt/git_repos
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER  #IMportant !!! This could be your problem if missing

<Directory /opt/git>  # both http_backend and gitweb should be somewhere under here
        AllowOverride None
        Options +ExecCGI -Includes  #Important! Lets apache execute the script!
        Order allow,deny
        Allow from all
</Directory>

# This pattern matches git operations and passes them to http-backend
ScriptAliasMatch \
        "(?x)^/git/(.*/(HEAD | \
                        info/refs | \
                        objects/(info/[^/]+ | \
                                 [0-9a-f]{2}/[0-9a-f]{38} | \
                                 pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                        git-(upload|receive)-pack))$" \
        /opt/git/libexec/git-core/git-http-backend/

# Anything not matched above goes to displayable gitweb interface
ScriptAlias /git /opt/git/cgi-bin/gitweb.cgi/

The result is the ability to push/pull:

结果是推/拉的能力:

me@machine /tmp/eddies $ git pull
Already up-to-date.

me@machine /tmp/eddies $ touch changedFile

me@machine /tmp/eddies $ git add .

me@machine /tmp/eddies $ git commit -am"commiting change"
[master ca7f6ed] commiting change
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 changedFile

me@machine /tmp/eddies $ git push origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 239 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
To http://mysecretdomain.com/git/eddies
   0f626a9..ca7f6ed  master -> master

And you can browse those changes online.. gitweb provides a browsable interface

您可以在线浏览这些更改。 gitweb 提供了一个可浏览的界面

Source: http://repo.or.cz/w/alt-git.git?a=blob_plain;f=gitweb/README

来源:http: //repo.or.cz/w/alt-git.git?a=blob_plain; f=gitweb/ README