To restrict force pushes to a branch on GitHub, you can use
branch protection rules. These rules prevent destructive actions like force-pushes (git push --force) to important branches like
main, master, or dev.
Steps to Restrict Force Pushes on GitHub
Go to your repository on GitHub.
Click on Settings (you must have admin access to the repo).
In the left sidebar, click Branches.
Under Branch protection rules, click "Add rule".
In the Branch name pattern, enter the name of the branch you want to protect (e.g.,
main or release/* for a pattern).
Enable the checkbox:
✅ "Do not allow force pushes"
(Optional) Enable other protections like:
Require pull request reviews
Require status checks to pass
Require linear history
Click Create or Save changes.
Result
Once this rule is applied:
All users will be blocked from using git push --force to that branch.
GitHub will return an error like:
"You cannot force push to a protected branch."
Tip: If you want to allow normal pushes but block only force pushes:
Don’t enable “Restrict who can push to matching branches” (unless you also want to control who can push).
Just enable “Do not allow force pushes.”
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
To restrict force pushes to a branch on GitHub, you can use branch protection rules. These rules prevent destructive actions like force-pushes (
git push --force) to important branches likemain,master, ordev.Steps to Restrict Force Pushes on GitHub
mainorrelease/*for a pattern).Result
Once this rule is applied:
git push --forceto that branch.Tip: If you want to allow normal pushes but block only force pushes: