代码之家  ›  专栏  ›  技术社区  ›  pistacchio

HTTP上的私有Git存储库

  •  15
  • pistacchio  · 技术社区  · 15 年前

    你能推荐任何一个简单的解决方案来建立一个可以通过HTTP(s)访问的Git存储库吗?克利特斯建议过吗?我有自己的HTTP服务器,我想用它来主持一些小型的私人项目。在家里我可以用ssh,但在工作时防火墙阻止我这样做。

    有没有任何自由的方法来建立一个小型的私有Git存储库,我可以通过HTTP推送/获取,这样我就可以在家和工作之间共享项目?事先谢谢!

    2 回复  |  直到 6 年前
        1
  •  21
  •   Steve Nay    15 年前

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

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

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

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

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

        2
  •  1
  •   HeatfanJohn Parkofadown    6 年前

    不需要WebDAV

    更重要的是,自Git1.6.6以来,DAV比新的“智能HTTP”支持慢得多。新方法允许一次性传输整个包,而不是作为单个文件进行传输。


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

    注意:由于访问由Apache控制,因此您可以向每个存储库的设置中添加任何身份验证要求(htaccess或ldap等)。


    只需制作一个新的git_support.conf文件,并将其包含在Apache中(在httpd.conf中添加include语句)。

    < PRE> >代码> #Git HTTP后端的基本设置 γ setenv git_项目_root/opt/git_repos setenv git_http_export_all(全部导出) setenv remote_user=$redirect_remote_user重要!!!!如果不见了,这可能是你的问题。 <directory/opt/git>http_后端和gitweb都应该在下面的某个位置 不允许使用 选项+Execcgi-包括重要!让Apache执行脚本! 命令允许,拒绝 允许来自所有 </directory> #此模式匹配Git操作并将其传递到HTTP后端 脚本别名匹配\ “?”x)^/Git/(.*/(头部|\ 信息/参考文献 对象/(信息/[^/]+|\ [0-9a-f]2/[0-9a-f]38 |\ 包装/包装-[0-9a-f]40 \(包装idx))。|\ git-(upload receive)-pack))$“。\ /opt/git/libexec/git core/git http后端/1美元 #上面不匹配的内容将转到可显示的GitWeb界面 脚本别名/git/opt/git/cgi bin/gitweb.cgi/

    结果是推/拉的能力:

    me@machine/tmp/eddies$git pull
    已经是最新的。
    
    ME@machine/tmp/eddies$touch changed文件
    
    me@machine/tmp/eddies$git添加。
    
    me@machine/tmp/eddies$git commit-am“提交更改”
    【CA7F6ED大师】承诺变更
    0个文件已更改,0个插入(+),0个删除(-)
    创建模式100644 ChangedFile
    
    me@machine/tmp/eddies$git push原始主机
    计数对象:3,完成。
    增量压缩最多使用8个线程。
    压缩对象:100%(2/2),完成。
    写入对象:100%(2/2),239字节,完成。
    总计2(增量1),重复使用0(增量0)
    至http://mysecretdomain.com/git/eddies
    0F626A9..CA7F6ED主控形状->主控形状
    < /代码> 
    
    

    您可以在线浏览这些更改。

    来源: http://repo.or.cz/w/alt-git.git?A=blob_plain;F=gitweb/readme

    自Git 1.6.6以来,他获得了新的“智能HTTP”支持。新方法允许一次传输整个包,而不是作为单个文件。


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

    注意:由于访问是由Apache控制的,所以您可以向每个存储库的设置中添加任何身份验证要求(htaccess或ldap等)。


    只需制作一个新的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/$1
    
    # Anything not matched above goes to displayable gitweb interface
    ScriptAlias /git /opt/git/cgi-bin/gitweb.cgi/
    

    结果是推/拉的能力:

    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
    

    您可以在线浏览这些更改。 gitweb provides a browsable interface

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