Unable to push to repository - "pre-receive hook declined" error

Still need help?

The Atlassian Community is here for you.

Ask the community

 

Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.

   

Summary

  • The purpose of this knowledge article is to detail why this error message may occur when attempting to push to a repository and provide steps on how to resolve this

Environment

  • Performing a GIT push to a repository hosted in Bitbucket Cloud

Diagnosis

  • You attempt to perform a GIT push to a Bitbucket Cloud repository that you have access to but instead of allowing the pushing to succeed - you receive some variant of the following error message and you are prevented from doing so:

    Error Message
     ! [remote rejected] main -> main (pre-receive hook declined)
    error: failed to push some refs to 'http://bitbucket.org/someworkspace/somerepository'

Cause

Branch permissions

  • A potential cause behind this error message is that branch permissions are configured against the target branch that are restricting write operations in some manner
  • The scenarios that would prevent pushing are as follows:
    1. The user account that you are trying to push from is not configured on the branch restrictions list
    2. You are using an access token to authenticate whilst branch restrictions are configured (this is currently not supported - please see the following feature request for further details: BCLOUD-22400)
    3. You are pushing using an SSH key added to your workspace instead of your personal account (If this is the case, the solution is to simply move the workspace SSH key to your personal SSH key settings instead)

GPG key enforcement

NOTE: This is a Premium feature and does not apply to Standard/Free workspaces

  • Another potential cause behind this error message is that signing your commits using a GPG key has been enforced as a security requirement on the repository that you are trying to push to 
  • If you do not sign your commit, the error message will display and will prevent you from performing a repository push

Solution

Branch permissions

The following steps will need to be performed by a repository administrator, if you do not have repository administrator permissions - you will need to reach out to a user who does and have them perform the steps outlined below.

  1. Navigate to Repository Settings > Branch Restrictions and verify that the target branch you are attempting to push to has restrictions configured against it
    (info) NOTE: If you are pushing using a repository/workspace/access token to authenticate with branch restrictions configured, this is currently not supported - please see the following feature request for further details: BCLOUD-22400

  2. Click the Edit button against the branch and observe the Write Access subheading, you should see that there is a restriction that only certain users or groups are able to perform write operations against that branch:
  3. The user who was unable to write to that branch will either need their name added to the list individually or they will need to be added to any user group that is already present in that list under the Only specific people or groups have write access option
    (info) NOTE: If the push involves re-writing branch history (for example a rebase operation), the Allow rewriting branch history option must also be ticked to allow users to perform such operations (see screenshot above)

  4.  Once all intended changes have been made, click the Save button to finalise the changes and attempt to perform a push to that branch again

GPG key enforcement

NOTE: This is a Premium feature and does not apply to Standard/Free workspaces

  1. Please reach out to your repository administrator to determine if the GPG commit signing enforcement setting has been enabled (if you are already an admin, check Repository Settings > Repository Details > Advanced and determine if the Require all commits to have a verified signature option is ticked)
  2. If the setting is enabled, you will need to ensure that you sign all of your commits using your GPG key as per the repository security requirements, you can learn how to do so by following our documentation:
    Use GPG keys to sign commits
  3. Once you push a signed commit, the error message should no longer display


If you are still encountering issues with pushing to your repository after following the steps within this article, please feel free to raise a support ticket or raise a community support ticket for further assistance.

DescriptionUnable to push to repository - "pre-receive hook declined" error
ProductBitbucket Cloud
Last modified on Dec 20, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.