413

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?

4
  • 10
    What's in the pre-receive hookon mycogit?
    – rob mayoff
    Nov 2, 2011 at 19:33
  • You wouldn't be trying to push large files to github would you? Sep 25, 2015 at 17:01
  • FYI: today all my colleague's got this errormessage, eventually we decided to restart our stash server and it got magically fixed. We have no idea what the issue actually was.
    – T_D
    Feb 7, 2017 at 16:08
  • First, you should check your branch permissions or white lists. Aug 9, 2021 at 7:55

45 Answers 45

225

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.

7
  • 11
    In my case, BitBucket had a validation of the commit message content, confronting it with the JIRA tickets, which was offline at that moment. May 17, 2016 at 16:44
  • 1
    so when it became online its fixed ?
    – shareef
    Oct 7, 2016 at 18:26
  • 12
    In my case it was a mismatch in the username with which the commits were generated and the username in BitBucket. I wasn't authorised to update BitBucket username, so I had to reset my commits and commit them again with updated username. You can update git username with this command git config user.name 'UpdatedUserName'
    – M M
    Jan 22, 2019 at 6:22
  • 3
    In our case bitbucket did not allow anyone to push to this branch. May 16, 2019 at 9:24
  • In my case I had to find the repo settings on bitbucket and disable the verify committer under the Hooks settings.
    – Sizons
    Aug 23, 2019 at 10:33
112

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

5
  • This helped as my problem was an unwanted SQL dump file (155mb in file size) was being pushed (by accident).
    – meewog
    Jul 15, 2016 at 9:48
  • 3
    The file size limit depends on your hosting provider. GitHub has a limit at around that size, for others it varies, and self-hosted git naturally doesn't have such limits.
    – 1615903
    Nov 16, 2017 at 11:00
  • 1
    what do you do if you already have several commits after the declined push? this is my case i have an unwanted large file(627MB) in one of the previous commits before trying to push to repo
    – CanCoder
    Jun 7, 2019 at 8:32
  • I had a CSV file being uploaded by accident. So in my case, the error was due to that.
    – tonhozi
    Jun 10, 2019 at 20:43
  • 2
    If you have several commits, increase the index to reset the head back to that commit. For example, use HEAD~3 to go back to three previous commits. Always use the --soft switch to maintain changes in the folder.
    – ozkary
    Jun 11, 2019 at 16:01
104

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.

2
  • This is awesome. Now I can again push and pull, but before it I need to set upstream as git branch --set-upstream-to=origin/myBranch. +1 for your answer.
    – AlokeT
    Mar 20, 2019 at 13:27
  • In a new repository I pushed a branch (not master), then rebased it and got the error during push. I didn't find web-hooks. I executed git pull --rebase, had to rebase again and was able to push the branch. Finally I found that my branch became protected.
    – CoolMind
    Nov 13, 2019 at 15:34
58

In my case I got this message because the branch was marked as 'Protected' in GitLab.

2
35

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.

1
  • I think this is correct, but whats interesting is VS seems to be trying to push to the parent branch not the actual branch name to the remote. So if the parent branch is protected this seems to be occurring but there doesn't appear to be anyway to correct this in VS and you have to switch to the cmd line.
    – Mark
    Jul 11, 2016 at 17:30
22

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

Allow rewriting branch history

2
  • 2
    On GitLab I've found this option under Settings -> Repository -> Allow all users with push access to force push.
    – RichardK
    Feb 1, 2022 at 14:34
  • I have added my user to Prevent rewriting history --> exemptions in bitbucket still getting error pre-receive hook declined for master as well branch derived from master, note I am migrating github repo so used fetch --all and changed remote to bitbucket repo Jul 1, 2022 at 11:09
19

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 .

:)

0
13

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.

2
  • 2
    Just had this issue and I guess GitLab were making changes. Gave it 10 minutes and it worked. I didn't change anything.
    – woter324
    May 3, 2019 at 0:04
  • Just had this issue as well. For anyone that might want to check if this is the case: status.gitlab.com Nov 26, 2019 at 16:58
7

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.

3
  • I couldn't push to the new branch neither
    – zabop
    Nov 22, 2018 at 11:46
  • Same here. git checkout -b test then git checkout master was all I had to do to get push privileges back. Then git branch -d test of course, to keep things clean :-)
    – Dan Weaver
    Nov 9, 2021 at 1:17
  • Same for me. Switching to and pushing from an old branch, then switching back to the branch fixed it. Once, again, don't ask how :) May 17 at 20:40
6

I had this issue when trying to merge changes with file size greater than what remote repository allowed (in my case it was GitHub)

1
5

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)
4

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.

0
4

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)

3

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.

1
  • Got this too. Turns out the repo had the file "snippets\\csharp.json" which gave git on windows a hard time.
    – Carl Walsh
    Dec 21, 2019 at 21:29
3

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.

2

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.

1
  • 1
    This answer is unlikely to help, as the original poster (and anyone else visiting in the future) will have a different script configured as a pre-receive hook.
    – aronisstav
    Feb 6, 2018 at 11:36
2

For me Authorization on remote git server solve the problem. enter image description here

2

Step1:

git pull --rebase

Step2:

git reset --soft HEAD~1

Step3:

git commit -m "your comments here"

Step4:

git push

This should fix your issue.

1
  • i had to go back several commits, but yeah, this did it for me
    – john k
    Nov 9 at 19:59
1

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.

1

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 Git push error pre-receive hook declined. I found that my branch became protected. I removed protection and could forcely push again.

enter image description here

1

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.

1

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.

2
  • What "git global file"? Do you mean ~/.gitconfig?
    – kelvin
    May 25, 2021 at 17:39
  • 1
    hey Kelvin, yes you are right its : git config --global user.name and git config --global user.email ; May 30, 2021 at 11:45
1

I resolved this issue with regenerating SSH key and adding it to the GitHub account.

1

My issue was file size, trying to migrate a project from gitlab to github, and the error did hint at it for me, directing to this page https://docs.github.com/en/repositories/working-with-files/managing-large-files/moving-a-file-in-your-repository-to-git-large-file-storage

The command used was:

git lfs migrate import --everything --above=100kb

After this I was able to git push --mirror http:...

0

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% /
0

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.

0

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.

0

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!

0

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
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.