403

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?

1615903
  • 32,635
  • 12
  • 70
  • 99
Dave
  • 15,639
  • 133
  • 442
  • 830

45 Answers45

221

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.

Hoang Pham
  • 6,899
  • 11
  • 57
  • 70
Alexander Gladysh
  • 39,865
  • 32
  • 103
  • 160
  • 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. – Vítor Neil Avelino May 17 '16 at 16:44
  • 1
    so when it became online its fixed ? – shareef Oct 07 '16 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 '19 at 06:22
  • 3
    In our case bitbucket did not allow anyone to push to this branch. – Ramon Fincken May 16 '19 at 09: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 '19 at 10:33
  • In my case, in BitBucket I had added the SSH Key to the repository's set of SSH Keys instead of to my account's set of SSH Keys. Once I removed the key from the Repository Settings and added it to Workspace settings all worked as expected. – David Hunt May 14 '20 at 10:43
  • In my case it was just a temporary glitch. I tried over again a few minutes later without changing anything and it worked. – Charlotte_Anne Feb 10 '21 at 22:14
109

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

starball
  • 20,030
  • 7
  • 43
  • 238
ozkary
  • 2,436
  • 1
  • 21
  • 20
  • This helped as my problem was an unwanted SQL dump file (155mb in file size) was being pushed (by accident). – meewog Jul 15 '16 at 09: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 '17 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 07 '19 at 08:32
  • I had a CSV file being uploaded by accident. So in my case, the error was due to that. – tonhozi Jun 10 '19 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 '19 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.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • 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 '19 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 '19 at 15:34
55

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

Dave de Jong
  • 859
  • 7
  • 13
32

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.

user5305519
  • 3,008
  • 4
  • 26
  • 44
yong
  • 379
  • 3
  • 5
  • 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 '16 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

gutte
  • 1,373
  • 2
  • 19
  • 31
  • 2
    On GitLab I've found this option under Settings -> Repository -> Allow all users with push access to force push. – RichardK Feb 01 '22 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 – Ashish Karpe Jul 01 '22 at 11:09
18

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 .

:)

hai jiang
  • 199
  • 1
  • 4
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.

Thomm
  • 506
  • 5
  • 12
  • 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 03 '19 at 00:04
  • Just had this issue as well. For anyone that might want to check if this is the case: https://status.gitlab.com/ – Renan Ferrari Nov 26 '19 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.

shapiro yaacov
  • 2,308
  • 2
  • 26
  • 39
  • I couldn't push to the new branch neither – zabop Nov 22 '18 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 09 '21 at 01: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 :) – Sidney Sousa May 17 '23 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)

serup
  • 3,676
  • 2
  • 30
  • 34
  • 3
    In my case even after deleting the file GitHub still complained... but this answer did the trick https://stackoverflow.com/questions/19573031/cant-push-to-github-because-of-large-file-which-i-already-deleted – CodenameDuchess Nov 17 '17 at 15:34
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)
medmek
  • 201
  • 3
  • 8
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.

diman82
  • 702
  • 8
  • 11
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)

Sandra Pavan
  • 194
  • 1
  • 2
  • 8
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.

Sergej Popov
  • 2,933
  • 6
  • 36
  • 53
  • 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 '19 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.

eTechman
  • 31
  • 2
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.

Aditya Deshmane
  • 4,676
  • 2
  • 29
  • 35
  • 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 06 '18 at 11:36
2

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

shdr
  • 868
  • 10
  • 25
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.

GoTo
  • 5,966
  • 2
  • 28
  • 31
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

CoolMind
  • 26,736
  • 15
  • 188
  • 224
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.

JoshuaRDBrown
  • 343
  • 5
  • 12
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.

1

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

Vitalina
  • 51
  • 9
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:...

001001
  • 530
  • 1
  • 4
  • 13
1

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.

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% /
frmdstryr
  • 20,142
  • 3
  • 38
  • 32
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.

Agnel Amodia
  • 765
  • 8
  • 18
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.

Dugini Vijay
  • 865
  • 7
  • 8
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!

Manuel Alanis
  • 346
  • 1
  • 8
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
Duc Filan
  • 6,769
  • 3
  • 21
  • 26
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.

TundraGreen
  • 51
  • 1
  • 3
0

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

Panagiotis Simakis
  • 1,245
  • 1
  • 18
  • 45
0

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:

  1. delete existing pull requests related to the problematic branches,
  2. delete the branches on server side,
  3. re-push from local to remote repo, and,
  4. create the pull request again.
deponovo
  • 1,114
  • 7
  • 23
0

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.

vijay9908
  • 59
  • 2
  • 2
    This doesn't really add anything that's not already mentioned in the two pages of answers. The top answer explains that it could be a hook managed by the organisation, and plenty of other answers specifically talk about Jira ticket numbers possibly being required. – DaveyDaveDave Mar 14 '22 at 22:30
0

In my case I manage the project myself but recently upgraded it to the hobbyist tier. In any case checked the logs through herokus browser interface and it had a very clear message about the node version (its an express app) not being defined in the package.json. They had a link to a heroku page outlining how to fix it and it worked.

In any case I just added this to my package.json and no further issues!

  "engines": {
    "node": "16.x",
    "npm": "6.x"
  },

I checked my node version and npm versions first though just to be clear. My node version was 16 but my npm version was 7. I decided to leave the npm defined as 6.x just because it's what was listed on the heroku page. Didn't encounter any issues.

$ node --version

$ npm --version

And here's the link to the heroku help page for this.

https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version

0

In my case, it was jira issue integration under project settings in BITBUCKET. By means, we need to put jira issue associated with it. I had two options 1) disable jira issue in the commit 2) put jira issue reference to the commit.

poza
  • 1
  • 1
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33425110) – Parisa.H.R Dec 21 '22 at 04:51
0

i had two different lock files in my app, deleting the unused one solved.

-1

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...

Jeffrey Ng
  • 67
  • 1
  • 7
-1

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

enter image description here

Jas
  • 794
  • 12
  • 22
-1

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.

Zeus
  • 6,386
  • 6
  • 54
  • 89
-1

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

Miles
  • 89
  • 1
  • 3
-1

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

themenace
  • 2,601
  • 2
  • 20
  • 33
-1

Simple and Quick fix:-

git commit -m "branch_name:added git script"

Kumar Pankaj Dubey
  • 1,541
  • 3
  • 17
  • 17
-1

! [remote rejected] master -> master (pre-receive hook declined)

I spend 2 days on this bug! After a lot of research, I finally found a solution for this.

  1. Heroku config:set USE_NPM_INSTALL=false
  2. Configured the yarn build pack on Heroku
  3. Make sure yarn.lock file is NOT in your .gitignore file

It will work!

Youba
  • 2,636
  • 3
  • 11
  • 25
-1

Tried most of the suggestion here. Didn't work (Github)

Just delete the .git file

rm -rf .git

reinitialize a new rebo

make sure to use

git push -u --force origin master

as the last step

Follow steps here: I know its destructive but iv tried everything else

-2

If you facing an issue related to pre-receive hook declined in git while doing Push. You may have the below reasons:

  1. Maybe your DB backup in your project path app_data is exceeded the 100.00 MB limit of Github.
  2. 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:

  1. Just do the zip those files and push again git push -u origin develop