Stop Force Pushes to Main with TowerGit Branch Protection
TowerGit branch protection blocks force pushes, requires reviews and status checks, keeping main stable and CI pipelines reliable.
10 Oct 2025, 06:12 UTC

Unstable merges break the main branch
A developer pushes a feature branch that has not passed review or the full test suite. When that branch lands on main, the build breaks and someone must roll back the change. The cost is wasted CI minutes and delayed releases.
The practical fix is to configure TowerGit branch protection so that main cannot accept a merge until defined quality gates pass. Branch protection is a repository setting that rejects pushes and merges that violate rules you choose.
Identify the branch to protect
Open the repository in TowerGit and select the branch that represents your production target, usually main or master. Open the protection settings for that branch. This tells TowerGit which ref is guarded.
Define the protection rules
Enable these rules to create a quality gate:
- Require status checks: the CI pipeline must report success before a merge.
- Block force pushes:
git push --forceis rejected on the protected branch. - Require pull request approvals: a set number of reviewers must approve before merging.
You can apply the same settings through the TowerGit CLI. Run this from a machine with organization-admin access:
towergit protection set \
--branch <BRANCH_NAME> \
--require-status-checks \
--require-pull-request-reviews 2 \
--block-force-push true
Replace <BRANCH_NAME> with your target branch, such as main. The command requires administrative rights; without them, TowerGit may accept the command but not enforce it.
Worked example: feature/login
- A developer creates
feature/loginand pushes commits. CI runs and passes. - The developer opens a pull request targeting
main. - TowerGit evaluates the protection rules. The merge button stays disabled until two reviewers approve and the CI status is green.
- After approvals and passing checks, a reviewer merges the pull request. TowerGit verifies that the merge does not include a force push and updates
main. - If someone attempts
git push --force origin main, TowerGit rejects the push with an error such as “protected branch: force push denied.”
Trade-off: safety can slow iteration
Strict protection prevents broken builds, but it can delay urgent fixes when reviewers are unavailable or CI checks are flaky. Also, users with repository-admin rights may bypass repository-level rules, so configure protection at the organization level when possible. TowerGit versions older than 2.5 do not support required commit signing; upgrade if you need that gate.
Verify the configuration
Open the TowerGit protection UI for main and confirm that “Require pull request reviews” is enabled. Then test from a terminal with write access:
git push --force origin <BRANCH_NAME>
The command should fail with a protection error. If it succeeds, the rule is not active or your account has bypass privileges.
Take action
Review your primary branch in TowerGit, enable the rules above, and test with a force push. Adjust the reviewer count and status-check requirements to match your team’s cadence. Revisit the settings after any repository migration, because TowerGit may reset protection toggles.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.