可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have run gitlabhq rails server on virtual machine, following 1-6 steps from this tutorial https://github.com/gitlabhq/gitlab-recipes/blob/master/install/centos/README.md and starts rails server executing command sudo -u git -H bundle exec rails s -e production
. After that I created user, using admin tools and created new project under this user. Then I'm trying to push the existing project to this repo as always. But in the last step, git push origin master
fails with the error
[remote rejected] master -> master (pre-receive hook declined)
Additional info:
1) I haven't activated user (project owner) via email activation link, because I haven't configured post service on server-side and I didn't find instructions how to do that in this manual.
2) Gitlab server generates tips how to push project to repo and there is not repositories/
in path. I mean it generates git@mygitlabhost:user/repo.git
instead of git@mygitlabhost:repositories/user/repo.git
which is correct.
3) When i tried to debug it, I opened pre-receive
script inside repo on server and tried to output variables (there is 3 of them): refs = ARGF.read
, key_id = ENV['GL_ID']
and repo_path = Dir.pwd
and found, that key_id is always empty. Maybe the problem is here... If so, please give me suggestions on how to fix that. Thanks
回答1:
GitLab by default marks master
branch as protected
(See part Protecting your code
in https://about.gitlab.com/2014/11/26/keeping-your-code-protected/ why). If so in your case, then this can help:
Open your project > Settings [> Repository tab] and go to "Protected branches", select: "Developers can push" and try again.
via https://gitlab.com/gitlab-com/support-forum/issues/40
For version 8.11 and above how-to here: https://docs.gitlab.com/ee/user/project/protected_branches.html#restricting-push-and-merge-access-to-certain-users
回答2:
Following resolved problem in my local machine:
A. First, ensure that you are using the correct log on details to connect to Bitbucket Server (ie. a username/password/SSH key that belongs to you)
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. If you were using the wrong account, simply switch your account credentials (username/password/SSH key) and try pushing again.
D. Else, if your local configuration incorrect you will need to amend it
For MAC
open -a TextEdit.app ~/.gitconfig
NOTE: You will have to fix up the old commits that you were trying to push.
Amend your last commit:
> git commit --amend --reset-author
<save and quit the commit file text editor that opens, if Vim then
:wq to save and quit>
Try re-pushing your commits:
> git push
回答3:
Seems the problem is with some services, like sidekiq. Running sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
outputs all the problems with config.
回答4:
In my case, my team lead to created a repo(repo was empty) and assign me as developer so when I pushed to the code directly to master the error I was facing ! [remote rejected] master -> master (pre-receive hook declined)
So how it was fixed that he assigned to me as maintainer so I was able to push the code directly to the master.
回答5:
You might not have developer access to the project or master branch. You need dev access to push new work up.
New work meaning new branches and commits.
回答6:
Might not be the case, but this was the solution to my "pre-receive hook declined" error:
There are some repositories that only allow modifications through Pull Request. This means that you have to
- Create a new branch taking as base the branch that you want to push your changes to.
- Commit and push your changes to the new branch.
- Open a Pull Request to merge your branch with the original one.
回答7:
You need to add your ssh key to your git account,if it throws error then delete previous ssh key and create a new ssh key then add.
回答8:
I solved this issue by changing remote 'origin' url
from http
to git
protocol in .git/config
回答9:
Go to Project settings --> Hooks --> (Under) Pre-receive hooks
Disable
cp require issue reference in commits
回答10:
To use npm to install your application's dependencies please delete the yarn.lock file.
To use yarn to install your application's dependences please delete the package-lock.json file.