Git history rewrite on Bitbucket [remote rejected] HEAD -> branch (pre-receive hook declined)
Asked Answered
I

2

15

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?

Infiltrate answered 4/11, 2014 at 10:2 Comment(0)
I
36

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.

Infiltrate answered 4/11, 2014 at 10:2 Comment(0)
P
1

I'm not sure but Bitbucket seems to be changed. In order to allow it, you should go to Repository settings and in WORKFLOW click on Branch restrictions, click to Edit the branch which you have tried to update and select Allow rewriting branch history:

Allow rewriting branch history

Pseudoscope answered 19/12, 2022 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.