![](/img/trans.png)
[英]How can I enable anonymous read access (pull) but authenticated write access (push) to a git repository over http?
[英]How can I allow anonymous push to a git repository over http?
将它添加到你的httpd.conf(假设/ srv / git包含你的repos)
<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
请注意,自git 1.6.6以来,DAV明显慢于新的“smart-http”支持。 新方法允许一次传输整个包,而不是单个文件。
下面的设置消除了每个repo(http.receivepack)中自定义配置的需要,或者需要进行硬重置。 只需将每个新的重新组合起来
git --bare init --shared
你也可以使用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
你可以在线浏览这些变化..
资料来源: http : //repo.or.cz/w/alt-git.git?a = blob_plain; f = gitweb / README
只是不要在Apache配置中放置任何AuthType
(因此没有LocationMatch
或Location
元素)。
如果您没有AuthType,这意味着您的Apache只会将您的git请求传递给cgi程序git-http-backend
。
因此,在这种情况下不会进行身份验证:匿名推送将是可能的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.