Git push is rejected using SSH key with branch restrictions
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
Git push is rejected whilst having write access in the repository branch restriction settings. The situation implies that there may be some issues with the branch restriction settings or the location of the Public SSH key being added to Bitbucket cloud.
Example error
1
! [remote rejected] feature/test-commit -> feature/test-commit (pre-receive hook declined)
Environment
Bitbucket cloud with SSH connection
Diagnosis
There are two places that need to be checked and verified for correct configuration:
Branch restriction settings
SSH key location
Start with the branch restriction settings first by identifying whether the user is in the group that is allowed to write to the branch. If not, manually add the user to the branch restriction settings.
If the above is correctly configured, identify where the Public SSH key was previously added. Check the following areas:
Personal Settings - https://bitbucket.org/account/settings/
Workspace Settings - https://bitbucket.org/<WorkspaceName>/workspace/settings/ssh-keys
Repository Settings - https://bitbucket.org/<WorkspaceName>/<RepoName>/admin/access-keys/
Solution
If you have added your public SSH key in the workspace or repository settings, kindly remove it from there and add it to your personal settings This is because branch restriction requires information about the user who is making the changes in order to verify if they have access to make changes on the branch or not. The push will be rejected if the user's identity is unknown.
Was this helpful?