On Bitbucket, using the Bitbucket web interface, I sync'd a blessed repo with my own private fork in error. I wanted to rewrite history on the blessed repo to bring it back to the correct commit.
I cloned the blessed repo that contained my incorrect commits and locally ran
git reset --hard HEAD~1
on the branch whose history was screwed up.
This brought the cloned repo back to the commit it was at before I screwed it up.
I then went to push my repo back up to Bitbucket using
git push -f origin development
but got the following error
remote: permission denied to force push branch development
To [email protected]:blessed-repo/blessed-repo.git
! [remote rejected] HEAD -> development (pre-receive hook declined)
error: failed to push some refs to '[email protected]:blessed-repo/blessed-repo.git'
Why did I get this error and how can I make the git push
work?
If your master branch is protected, you will get the gitlab ! [remote rejected] master -> master (pre-receive hook declined) error. Unprotect your master branch to solve the issue. If you can't push code directly to the master and get errors, you need to be the maintainer of the repo.
Pre-receive hook declined error happens because of multiple reasons, like comprise the rejection of commits and blockage of a non-fast-forward push. Apart from these reasons, invalid file size and the absence of an access right to push commits also contribute to the occurrence of the error.
A commit gets rejected and causes a failed to push some refs to error because the remote branch contains code that you do not have locally. What this means is that your local git repository is not compatible with the remote origin. Based on the above, your local machine is missing commits C and D.
At the command line, make sure you've changed into the repository directory. Enter git push at the command line to push your commits from your local repository to Bitbucket.
In Bitbucket, it is possible to limit push powers broken-link use branch permissions to prevent users from pushing to a branch directly.
From the above (old, no longer available) docs ...
Users are free to interact with a branch in their local clone. When they attempt to push to the Bitbucket remote, users who aren't allowed to push to the branch receive a message that the remote rejected the push.
You can see how this would be useful to enforce typical work flows.
To enable direct pushing to a branch on a repo
goto
Repo > Settings > Branch management > Prevent history re-writes (rebase) on these branches
then on that page, remove the branch that you are pushing to.
This will then enable you run git push origin +HEAD
Then you should re-add the branch to the list to prevent random pushes to the repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With