Reputation: 4487
My git push
to my remote Bitbucket server failed with:
! [remote rejected] master -> master (pre-receive hook declined)
I think it's a different issue than this (remote rejected master -> master (pre-receive hook declined)), and many people are facing the same issue, so I am posting a new question here.
My friend added me on bitbucket.org as an admin so that I can help on his project. So, I wanted to start by pulling the latest code to my local computer.
Steps I followed:
git init
git remote -v
(this gives nothing)git remote add origin <path to git repo>
git remote add master <path to git repo>
git remote -v
(this show both with fetch and push in brackets)git fetch origin master
git pull origin master
(I have latest code now, all files and folders)touch test
(lets test a "test" commit)git status
git add .
git commit -m "testing, first commit"
git push origin master
error:
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 274 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: permission denied to update branch master
To '<repo path>'
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '<repo path>'
Upvotes: 56
Views: 170961
Reputation: 52777
Write access
None
to Everybody
.git push
to push a new branch with a normally-protected name to the remote git server.
# Example
git push -u origin release/v1.2.3
None
after you're done, to prevent people from pushing commits directly to these branches with git push
. This ensures they must go through the PR (Pull Request) process.If git push
to a remote Bitbucket Cloud git server fails with the following error message:
! [remote rejected] release/v1.2.3 -> release/v1.2.3 (pre-receive hook declined)
...then it may be due to permissions issues.
Of the big 3 git hosting services (GitHub, GitLab, Bitbucket), Bitbucket Cloud seems to be the least developed, so you may have a conundrum:
You want to protect your main
and release/*
branches from direct pushes, but doing so also accidentally blocks you from creating new release/*
branches :(.
You go to https://bitbucket.org/mycompany/workspace/projects/myproject/settings/branch-restrictions
...and protect the main
and release/*
branches as follows, with Write access
set to None
:
This is good! It prevents people from pushing to these branches so they can't skip the PR (Pull Request) process. Now, the only way to get code into these branches is to create a PR and have it reviewed.
However, the conundrum is that this also blocks you from creating new release/*
branches, such as release/v1.2.3
. You can't push them to the remote server because of the permissions issue, and you get the error above.
While other git hosting services have this solved, Bitbucket Cloud does not yet.
So, to push a new release branch under a normally-protected branch name, do the following:
Go to your project or repo branch restrictions settings. Ex: https://bitbucket.org/mycompany/workspace/projects/myproject/settings/branch-restrictions
Click the Edit
link in the image above, for release branches.
You'll see this:
Uncheck the option which says Only specific people or groups have write access
, and change it to Everyone with access to the repository has write access
instead.
Click Save
.
Now you can push your new release branch to the remote server.
git push -u origin release/v1.2.3
Now go back to the branch restrictions settings and change it back to Only specific people or groups have write access
.
Done.
In this way, you are using the branch permissions set online as a sort of write protection "mutex" to prevent people from pushing directly to these branches, but you can temporarily disable this write protection when you need to create and push a new release/*
branch, such as release/v1.2.3
.
In Bitbucket Cloud, there should be, but currently isn't, an option to allow creating new branches even if Write access
is set to None
to block pushing new commits directly via git push
. I hope Bitbucket adds this feature in the future. I believe GitHub and others already have it.
Upvotes: 0
Reputation: 1063
I wanted to force push on my ticket branch, and it was rejected.
Went to Repository settings
-> Hooks
-> found out that Reject Force Push
was enabled, and disabled it.
Use at your own risk.
Upvotes: 0
Reputation: 147
Another scenario -> I also had this issue and I also configured global parameters, tried branching etc but it didnt work for me.
Below was the issue -> I recently joined my current firm and till my Bitbucket credentials got activated, I was using someone elses credentials to access Jira, Bitbucket etc. Now this credetials got saved in Windows inside "Credential Manager". After deleting those other colleague credentials, it worked fine for me.
Upvotes: 0
Reputation: 92467
I have a better solution on Bitbucket: If you are admin go to Repo >Settings >Limit Pushes section, and in "Branch name" put 'master', and in "..search... user" put your user name - then push "ADD" - and you are done :)
Upvotes: 2
Reputation: 22356
It looks like the branch management (one of the admin settings) in bitbucket has been configured to only allow certain people to push directly to master.
Try creating a branch - git checkout -b test
, create your test commit and push git push origin test:test
. You can always cleanly delete this branch once you have completed the test.
The other option (probably best agreeing with whoever set this up) is you go to bitbucket
and head to admin, branch management and remove master
be too limited. cf - https://confluence.atlassian.com/display/BITBUCKET/Branch+management
Upvotes: 61
Reputation: 2375
The same issue with me on gitlab, I asked the repo owner to grand me maintainer
role and the issue fixed.
Upvotes: 0
Reputation: 636
Just reporting another case leading to the specified error. If the Bitbucket repository size reaches 2 GB, Bitbucket itself restricts the repository to read-only access. When that happens, contributors with read/write permissions are not able to push and get the "pre-receive hook declined" error.
I also found these documents from Atlassian: https://blog.bitbucket.org/2014/05/30/repository-size-limits/ https://confluence.atlassian.com/bitbucket/reduce-repository-size-321848262.html
Links include a guide on how to restore the repo back to full functionality
Upvotes: 5
Reputation: 2066
What worked for me was:
Upvotes: -2
Reputation: 1654
I think package setuptools/distribute is listed in requirements.txt. Please remove the same.
Upvotes: 1