I was having a look at the history of my main branch in Git today, and I noticed that, despite the fact that I've configured branch protection of the main branch, and only allowed merging squash commits for PRs, one specific developer was able to commit changes to main.
So, I caught up with the developer to understand what was going on, and they were using this peculiar process to merge their code in:
- They were creating a PR, and waiting for approval and comments resolution as usual
- Once the PR was approved, instead of pressing the "Squash and merge" button in GitHub UI, they were:
- opening to their terminal
- switching the current branch to
main - merging their PR branch in
main - do a git push
I triple checked with the developer and:
- They cannot push to the
mainbranch normally, as expected - They only had squash merge as the only option in GitHub UI, as expected
This are my settings in GitHub:
I am puzzled:
- Why does this approach circumvent the rules configured in GitHub?
- Why is the developer even able to push into master in the first place (even if the branch they're trying to push has been PR'd)?
- Apart from asking to use the UI, is there anything I can actually do to prevent this behavior?


Restrict who can push to matching branchesSo long as the user is not an Organization administrator, repository administrator, and user with the Maintain role this will work and prevent this CLI ff method for regular users.