我已经在虚拟机上运行了gitlabhq rails服务器,遵循本教程https://github.com/gitlabhq/gitlab-recipes/blob/master/install/centos/README.md中的1-6步,并启动rails服务器,执行命令sudo -u git -H bundle exec rails s -e production。之后,我创建了用户,使用管理工具,并在此用户下创建了新项目。然后,我试图像往常一样将现有项目推到这个回购。但在最后一步,git push origin master失败,并出现错误

[远程拒绝]master -> master(预接收钩子拒绝)

额外的信息:

1)我还没有通过电子邮件激活链接激活用户(项目所有者),因为我还没有在服务器端配置post服务,我没有找到如何在本手册中做到这一点的说明。

2) Gitlab服务器生成提示如何推送项目到repo,没有repositories/ in路径。我的意思是它生成git@mygitlabhost:user/repo。Git代替git@mygitlabhost:repositories/user/repo。Git是正确的。

3)当我试图调试它时,我在服务器上的repo中打开了预接收脚本,并尝试输出变量(有3个):refs = ARGF。read, key_id = ENV['GL_ID'] and repo_path = Dir。PWD和发现,key_id总是空的。也许问题就在这里……如果是这样,请给我建议如何解决。谢谢


当前回答

尽管这个问题是特定于gitlab的,但类似的错误也会发生在github上,这取决于它是如何设置的(通常是github Enterprise)。

您需要熟悉以下概念:

pre-receive钩子 组织人 人则

webhook比其他两个项目更容易理解。

预接收钩子

是运行在GitHub企业服务器上的脚本吗 执行政策。当发生推送时,每个脚本在一个 孤立的 环境 以确定是否接受或拒绝推送。

组织人:

Webhook事件也从你的存储库发送到你的“组织Webhook”。更多信息。

这些都设置在你的github企业。它们是特定于github企业版本的。 由于您的访问限制(开发人员、维护人员、管理员等),您可能没有可见性。

其他回答

可能不是这样,但这是我的“pre-receive hook declined”错误的解决方案:

有一些存储库只允许通过Pull Request进行修改。这意味着你必须这么做

创建一个新分支,以您想要将更改推入的分支为基础。 提交并将更改推送到新分支。 打开一个Pull Request来合并你的分支和原来的分支。

您可能没有开发人员访问项目或主分支的权限。你需要开发权限来推动新工作。

新的工作意味着新的分支和提交。

以下是我本地机器中解决的问题:

A.首先,确保您使用正确的登录细节连接到Bitbucket服务器(即。您的用户名/密码/SSH密钥)

B. Then, ensure that the name/email address is correctly set in your local Git configuration: Set your local Git configuration for the account that you are trying to push under (the check asserts that you are the person who committed the files) * Note that this is case sensitive, both for name and email address * It is also space sensitive - some company accounts have extra spaces/characters in their name eg. "Contractor/ space space(LDN)".  You must include the same number of spaces in your configuration as on Bitbucket Server.  Check this in Notepad if stuck.

C.如果您使用了错误的帐户,只需切换您的帐户凭据(用户名/密码/SSH密钥),然后重试。

D.否则,如果您的本地配置不正确,您将需要修改它

对于MAC

打开一个TextEdit。应用~ / .gitconfig

注意:您必须修复您试图推送的旧提交。

修改上次提交: > git commit - modify -reset-author    <save并退出打开的提交文件文本编辑器,如果Vim then :wq保存退出> 尝试重新推动你的提交: > git push

GitLab默认将主分支标记为受保护(请参阅https://about.gitlab.com/2014/11/26/keeping-your-code-protected/ why中的保护代码部分)。如果你的情况是这样,那么下面的方法会有所帮助:

打开你的项目> Settings > Repository,进入“Protected branches”,在列表中找到“master”分支,然后点击“Unprotect”再试一次。

通过https://gitlab.com/gitlab-com/support-forum/issues/40

8.11及以上版本的操作指南请访问:https://docs.gitlab.com/ee/user/project/protected_branches.html#restricting-push-and-merge-access-to-certain-users

我在使用BitBucket时偶然发现了同样的错误。我有一个本地的Git回购,我想在线备份,所以我从我的BitBucket帐户创建了一个新的存储库(使用web界面)。

运行git后远程添加origin git@bitbucket.org:StatMarianne/<a private repo>。我运行git push origin master没有任何效果(我通常不会在git push中使用-u选项,因为我不介意在推拉时输入完整的repo和分支名称)。

错误如下:

remote: You're not allowed to write to this repository.
To bitbucket.org:StatMarianne/<a private repo>.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@bitbucket.org:StatMarianne/<a private repo>.git'

但是当我运行git push -u origin master(严格按照BitBucket的指示)时,我的本地分支确实被成功推送了。

我发现这很令人惊讶,因为-u(——set-upstream)应该只“添加上游(跟踪)引用…”不管怎样。