Git error when trying to push -- pre-receive hook declined
GitGit Problem Overview
When I try and push a change I've commited, I get the following error ...
git.exe push -v --progress "origin" iteration1:iteration1
remote: *********************************************************************
To ssh://git@mycogit/cit_pplus.git
! [remote rejected] iteration1 -> iteration1 (pre-receive hook declined)
error: failed to push some refs to 'ssh://git@mycogit/cit_pplus.git'
What's going on?
Git Solutions
Solution 1 - Git
You should ask whoever maintains the repo at git@mycogit/cit_pplus.git
.
Your commits were rejected by the pre-receive
hook of that repo (that's a user-configurable script that is intended to analyze incoming commits and decide if they are good enough to be accepted into the repo).
It is also a good idea to ask that person to update the hook, so it would print the reasons for the rejection.
If the maintainer is you yourself, then it looks like you've got a problem with your setup on the server-side. Please share more information then.
Solution 2 - Git
I'd bet that you are trying a non-fast-forward push and the hook blocks it. If that's the case, simply run git pull --rebase
before pushing to rebase your local changes on the newest codebase.
Solution 3 - Git
File size is important. There is a limit of ~120MB for a single file. In my case, .gitignore using Visual Studio had the file listed, but the file was still committed. When using the git cli, we can get more detail information about the error.
pre-receive hook declined was as a result of the big file. Basically validating the push.
To resolve it, I removed the last commit using:
git reset --soft HEAD~1
I then excluded the file from the commit.
Note: Use HEAD~N to go back to N number of previous commits. (i.e. 3, 4) Always use the --soft switch to maintain changes in the folder
hope it helps.
Solution 4 - Git
In my case I got this message because the branch was marked as 'Protected' in GitLab.
Solution 5 - Git
This may be because you didn't have the access right to push a commit to a branch such as master
. You can ask the maintainer to give you the right to push commits.
Solution 6 - Git
in sometimes, because the branch you are pushing has been protected, so you can ask the repository's maintainers to change the protecting status. in git-lab , you can find it in
Settings > Repository > Protected Branches .
:)
Solution 7 - Git
On my case (Bitbucket), the problem was Rewriting branch history is not allowed
restriction.
Go to Repository settings -> Branch Permissions
edit the selected branch's permissions, and check Allow rewriting branch history
Solution 8 - Git
I got this message when the GitLab server was undergoing some changes. The next day pushing worked fine. Anyways, as others pointed out, check with your maintainer to be sure.
Solution 9 - Git
I encountered this same issue.
What solved it for me was to switch to another branch and then back to the original one.
Not sure what the underline cause was, but this fixed it.
Solution 10 - Git
I had this issue when trying to merge changes with file size greater than what remote repository allowed (in my case it was GitHub)
Solution 11 - Git
In case it helps someone :
I had a blank repo with no master branch to unprotect (in Gitlab) so before running git push -u origin --all
- I had to run
git push -u origin master
first, - unprotect the master branch temporarily
- push the rest (
--all
&--tags
)
Solution 12 - Git
Bitbucket: Check for Branch permissions in Settings (it may be on 'Deny all'). If that doesn't work, simply clone your branch to a new local branch, push the changes to the remote (a new remote branch will be created), and create a PR.
Solution 13 - Git
I faced the same error, upon checking I had a developer access and couldn't publish a new branch. Adding higher access rights resolved this issue.(Gitlab)
Solution 14 - Git
I got this error with GitHub gist. I was trying to push a commit with files in sub-directories. Turned out gist can only have files in root directory.
Solution 15 - Git
Remove the protected branch option or allow additional roles like developers or admins to allow these users experiencing this error to do merges and push.
Solution 16 - Git
In my case, we have hooks for commit messages, our server script accepts commits if they have the special format for commit message"<JIRA ID><Message>"
. It(hook) declines commit if respective Jira ticket does not exist or there are some special symbols in the commit message. I face this error when I add /, [, > etc. in a commit message, removing those works fine.
Solution 17 - Git
Solution 18 - Git
I was using GitKraken and we made a local branch, then we merged two remote branches in it and then we tried to push the local branch to origin. It didn't work with the same error message.
The solution was to create the local branch and push it first to origin and then do the merge.
Solution 19 - Git
In my case I got this error because a branch with the same name already existed. Deleting this branch off of the git server will fix this.
Solution 20 - Git
I got this when trying to push to a dokku instance. Turns out the disk was full on my server.
Ran:
du -f
And result was:
Filesystem Size Used Avail Use% Mounted on
udev 476M 0 476M 0% /dev
tmpfs 100M 4.4M 95M 5% /run
/dev/xvda1 7.8G 7.4G 8.9M 100% /
Solution 21 - Git
This is actually happens when YACC is enabled at server side in BitBucket. YACC is enable for JIRA issue names to be mentioned in the commit message. So whenever you commit anything atleast keep your JIRA number into the commit message and then additionally you can add your own message.
Solution 22 - Git
Issue: "PUSH Failed refs/head/ - pre-receive hook declined"
I've faced the problem of unable to push my changes to my origin branch and anything to master branch of a particular project repository as the size of that repo was over hard limit of 2GB. It was throwing the error. That's because we had pushed the test data unknowingly to bitbucket from other testing branches.
> PUSH Failed refs/head/ - pre-receive hook declined
So tried checking is that the same with other project repo's and they weren't having any issues.
Fix:
My colleague noticed that when we cloned the project back locally, the size of the project was 110MB. So then we started cleaning the branches we merged earlier and active branches which are no more required. Once that cleaning is done for couple of branches we realized the size of the repo went drastically down from 2GB to 120MB. Then we tried to push the changes to my branch and it worked.
Solution 23 - Git
The error for me was that the project did not have any branches created, and my role was developer, so I could not create any branch, request that they give me the pertinent permissions and everything in order now!
Solution 24 - Git
A default branch (e.g. master
) does not yet exist for your remote. So you first need to create master
branch in the git remote server (e.g. creating a default README.md
file) then try to push
all your existing local branches using this command:
git push -u origin --all
Solution 25 - Git
In my case I had a new repository, pushed a branch ('UCA-46', not 'master'), rebased it, forcely pushed again and got the error. No web-hooks existed. I executed git pull --rebase
as @ThiefMaster advised, had to rebase again and was able to push the branch. But that was a strange and difficult way.
Then I saw https://stackoverflow.com/questions/28318599/git-push-error-pre-receive-hook-declined/46427322. I found that my branch became protected. I removed protection and could forcely push again.
Solution 26 - Git
I got this message while trying to delete a remote branch (git push origin --delete [branch-name]). The problem was that the branch was marked un-deletable in bitbucket.
Solution 27 - Git
Your commit is not compatible with the repository maintainer's rules, you just need to git reset --hard HEAD ~ 1
in order to delete the last commit. After that commitment according to the maintainer's rules is ok
Solution 28 - Git
In my case there was a Committer restriction in a project on Gitlab:
> Users can only push commits to this repository that were committed with one of their own verified emails.
Since I also configured SSH on my machine, my global_user_email was updated in the git config file with my machine's address, hence the remote was not allowing to push.
You can find this at:
- Gitlab -> Settings -> Repository -> Push Rules
Just disable the commit restriction and it will work.
Solution 29 - Git
This is a rather old question and has many answers already. But I would like to share the solution that worked for me while working with bitbucket (no admin rights). Most of my colleagues (to the exception of one) did not face any issues. The both of us could suddenly not push to precise branches any longer (I could not figure out the actual reason). The solution was:
- delete existing pull requests related to the problematic branches,
- delete the branches on server side,
- re-push from local to remote repo, and,
- create the pull request again.
Solution 30 - Git
I resolved this issue with regenerating SSH key and adding it to the GitHub account.
Solution 31 - Git
I got the same error ! [remote rejected] ... (pre-receive hook declined)
today.
It was caused by Bitbucket having a problem. So make sure that your Git Remote is up and running.
The issue that prevented me from pushing was: https://bitbucket.status.atlassian.com/incidents/r8kyb5w606g5
Solution 32 - Git
If in a corporate gitlab/ github and you trying to push changes to a branch/master, Pre-hook could mean that you missed some parameters input into the commit message.
In my case, along with message i was needed to add bug id, bug url and approver in commit file and then push to branch and place the merge request.
Hope this helps, as when writing commit message ask your mentor/buddy for th e requirements in a commit message.
Solution 33 - Git
Simple and Quick fix:-
> git commit -m "branch_name:added git script"
Solution 34 - Git
In my case, it's because I accidentally added a giant file to my uncommitted push and I could not get rid of it no matter whatever pull or reset or rm I did after.
my dirty solution but workable solution is to rename the current directory, re-clone the directory to local and reflect the changes manually to the recloned local directory...
It does not sound good but works...
Solution 35 - Git
For me everything was working fine until Bitbucket automatically changed their policy today (April 21, 2020). This happens to align with a new feature recently introduced today called Workspaces, so I suspect it has something to do with that.
Workaround: I (as an Admin) followed the instructions to add the email address to Users in the UI (the email you are using can be found git config --list
Solution 36 - Git
I had permissions issue, after given the right permissions i was able to push the contents. I was pushing a existing project into a new git repo.
Solution 37 - Git
You should look at the logs. I just ran into the same error and realized from the logs it was because I had a yarn.lock and package-lock.json
Solution 38 - Git
I had a similar issue and it was caused by bcrypt npm package. I uninstalled bcrypt and instead installed bcryptjs.
npm install --save bcryptjs && npm uninstall --save bcrypt
It's the exact same API. All the code inside app.js remains same except the require call need to be changed to require("bcryptjs");
Solution 39 - Git
If you facing an issue related to pre-receive hook declined in git while doing Push. You may have the below reasons:
- Maybe your DB backup in your project path app_data is exceeded the 100.00 MB limit of Github.
- Check the size of your file if you using it in your project not exceeded the size limit of 10.00MB or any file.
You can resolve this issue by the below steps:
- Just do the zip those files and push again git push -u origin develop