Reset on master branch

Sometimes in working on your projects you need to undone some unwanted commits made to master branch. I will show how to do it with GitLab repo.

If you follow regular workflow with git reset to reset to some commit

git reset --hard <commit_hash>
git clean -f -d

and then force push to master to reflect changes on remote repo

git push -f origin main

you can get error

remote: GitLab: You are not allowed to force push code to a protected branch on this project.To! [remote rejected] main -> main (pre-receive hook declined)error: failed to push some refs to ''

You need to obtain rights to force push to protected branch.

If you are maintainer go to Settings > Repository. Expand Protected branches, find master branch in list and move switch for option Allowed to force push

Thats it.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store