I have run gitlabhq rails server on virtual machine, following 1-6 steps from this tutorial 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
21 Answers
GitLab by default marks master branch as protected (See part Protecting your code in why). If so in your case, then this can help:
Open your project > Settings > Repository and go to "Protected branches", find "master" branch into the list and click "Unprotect" and try again.
For version 8.11 and above how-to here:
7Answer recommended by GitLab
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.
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
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.
This is because Master branch is protected, Here are the steps to clear this error.
- Create a branch in your master branch
git checkout -b new-branch-name - Push the new branch
git push --set-upstream origin new-branch-name - Now remotely merge the branch into master.
- Once merged, reset the local master branch
git reset --soft HEAD~1 - Finally
git pull
ihave followed the instruction of heroku logs img ( use cmd: heroku logs -> show your error) then do the cmd: "heroku buildpacks:clear". finally, it worked for me!
0Might 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.
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.
4You 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.
Go to Project settings --> Hooks --> (Under) Pre-receive hooks
Disable cp require issue reference in commits
I stumbled across the same error using BitBucket. I had a local Git repo I wanted to back up online, so I created a new repository from my BitBucket account (using the web interface).
After running git remote add origin :StatMarianne/<a private repo>.git, I ran git push origin master to no avail (I typically don't use the -u option with git push because I don't mind typing up the full repo and branch names when pushing and pulling).
The error read:
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 ':StatMarianne/<a private repo>.git' But my local branch did get successfully pushed when I ran git push -u origin master (following strictly BitBucket's instructions).
I find it surprising, since -u (--set-upstream) should only "add upstream (tracking) reference..." Anyhow.
Despite the question is specific to gitlab, but similar errors can happen on github, depending how it is set up (usually Github Enterprise).
You need to familiarize yourself with the following concepts:
- pre-receive hooks
- organization webhooks
- Webhooks
Webhooks are more commonly understood than other two items.
The Pre-receive hooks
are scripts that run on the GitHub Enterprise server to enforce policy. When a push occurs, each script runs in an isolated environment to determine whether the push is accepted or rejected.
Organization webhooks:
Webhook events are also sent from your repository to your "organization webhooks". more info.
These are set up in your github enterprise. They are specific to the version of the github enterprise. You may have no visibility because of your access limitations (developer, maintainer, admin, etc).
1I solved this issue by changing remote 'origin' url from http to git protocol in .git/config
I had the same problem while working with Bitbucket.
On push, the error was 'The commit message doesn't match the regex **".
Got to 'Settings' > 'Hooks' > Enable 'Yet another commit checker' option.
And it started working!!
1Please try:
git push -u origin master If you still aren't able to push successfully, Make a new branch or choose another one and Push on the new Branch
I've experienced that just because of AWS breakage.
To exclude this just check if the message contains something similar to
<head><title>504 Gateway Time-out</title></head>
So if you haven't done anything suspicious before and just started to see this - it may be just server timeouts.
If you are facing issue like
! [remote rejected] master -> master (pre-receive hook declined)
its beacuse master is protected, you can do 2 steps
To remove the protection, follow these steps –
Go to project Settings.
Click on Repository tab.
Open Protected Branches.
Find your master branch and click on Unprotect.
Or else
We can switch branches from master to main
git checkout -b main
git branch -D master
git push heroku main
Happy Hacking!!!
TL;DR Rename project and copy all the changes over.
I tried almost all answers on this page.
In the end I fixed it by doing this:
- Renaming my project to
project-tmp - Cloning the project again to
project - Manually moving all my changes from
project-tmptoproject(and not copying over the.git-folder obviously). git add .git commit -m 'Blah blah'git push
That worked!
Why this worked?
My theory is, that somewhere in some commit (or something) there was a bad piece of settings that screwed it up.
Git LFS
Another thing, that I did, was that I setup git lfs. I'm not sure if that was important or not.
For me two possible cases:
- The branch is protected and you do not have the right to push (see the role of your git user)
- Allowed to force push is disabled on this branch and you maybe you are trying to force push.
I've faced the same issue, this is because I am pushing my code directly in the master branch, and I don't have rights for this. So I push my code in a new branch and after that, I created a pull request to merge with master.
Please check if JIRA status in "In Development". For me , it was not , when i changed jira status to "In Development", it worked for me.