【问题标题】:How can I allow anonymous push to a git repository over http?如何允许通过 http 匿名推送到 git 存储库?
【发布时间】:2011-08-20 15:09:13
【问题描述】:

我在这里找不到示例: http://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html

有可能吗?

【问题讨论】:

    标签: apache git


    【解决方案1】:

    将此添加到您的 httpd.conf(假设 /srv/git 包含您的存储库)

    <Directory "/usr/lib/git-core*">
        Order allow,deny
        Allow from all
    </Directory>
    
    SetEnv GIT_PROJECT_ROOT /srv/git
    SetEnv GIT_HTTP_EXPORT_ALL
    ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
    

    然后确保 apache 可以写入您的存储库目录(从 repo 内部运行这里 http 是您的 apache 用户)

    chown -R http .
    

    在您在服务器上创建的存储库中打开 .git/config 并添加以下内容

    [http]
        receivepack = true
    

    最后在仓库根目录运行

    git config --bool core.bare true
    

    或者,如果您想要服务器上可用的文件(用于网站或其他),则忽略上述命令并使用此编辑 .git/config

    [receive]
        denyCurrentBranch = false
    

    然后当你想更新目录时在服务器上运行它(必须有更好的方法所以请告诉我)

    git reset --hard
    

    【讨论】:

      【解决方案2】:

      使用 git-http-backend 和 gitweb 进行匿名推送和浏览

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

      下面的设置消除了在每个 repo (http.receivepack) 中进行自定义配置的需要,或者不需要硬重置。只需使用

      制作每个新的 re[po
      git --bare init --shared
      

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

      注意:由于访问是由 apache 控制的,因此您可以将任何 Auth 要求(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
      

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

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

      【讨论】:

      • 感谢SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER 行。我花了一个小时在谷歌上搜索为什么我在配置其他所有内容时得到 403。
      【解决方案3】:

      只是不要在您的 Apache 配置中添加任何 AuthType(所以不要使用 LocationMatchLocation 元素)。

      如果您没有 AuthType ,这意味着您的 Apache 将简单地将您的 git 请求传递给 cgi 程序 git-http-backend
      所以在这种情况下不会进行身份验证:匿名推送将是可能的。

      【讨论】:

      • 您好 VonC,我没有 AuthType,但我仍然收到此消息 error: Cannot access URL http://localhost/git/test/, return code 22 来自该位置的 git clone 工作正常
      • @tm1rbt:保留 2 个 &lt;LocationMatch &gt; 元素及其 Options +ExecCGI,但没有其他内容(与身份验证相关),这应该有效。关键是要确保CGI执行完毕,否则依赖WEBDAV,会触发错误22。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-16
      • 2011-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多