Ask Before Bypassing Rule Violations #118558
Replies: 3 comments 1 reply
-
not very sure but here is the suggestion of Copilot, You're correct that Git itself does not provide a built-in mechanism for enforcing branch protection rules on the client side. These rules are enforced on the server side by services like GitHub, GitLab, Bitbucket, etc. However, you can achieve a similar effect using pre-push Git hooks. A pre-push hook script runs on your local machine before a Here's a simple example of a pre-push hook that asks for confirmation before pushing to the #!/bin/bash
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
read -p "You're about to push to $protected_branch, are you sure? (y/n) " -n 1 -r < /dev/tty
echo
if echo $REPLY | grep -E '^[Yy]$' > /dev/null
then
exit 0 # push will execute
fi
exit 1 # push will not execute
else
exit 0 # push will execute
fi To use this script, you would need to put it in the Please note that this is a very basic script and does not cover all possible scenarios. For example, it does not handle the case where you're pushing a different local branch to the remote Also, this script does not enforce the branch protection rules defined on the server. It simply asks for confirmation before pushing to |
Beta Was this translation helpful? Give feedback.
-
I also think such a feature would be great (at least I'd be interested in it 😄). While you can already select who can bypass branch protection rules, you cannot ensure that they did not bypassed them by mistake. All of this to say that I support this idea of having the possibility to ask for an explicit confirmation before bypassing branch protection rules (or any other way to make sure this is done intentionally, e.g. only allow force pushes to bypass protection rules). 👍 |
Beta Was this translation helpful? Give feedback.
-
👋 Way late to the party here. Getting an approval flow inline is good feedback, but I'm not sure it's something we'll get to right now. There is an option in ruleset to allow bypasses only in a PR. So the CLI would block on rule violations, unless you are pushing to an unprotected branch and then you can merge the PR bypassing all the requirements. We're also thinking about how we expand the delegated bypass scenarios from push rules for PR scenarios, but don't have an ETA for that. |
Beta Was this translation helpful? Give feedback.
-
Select Topic Area
Product Feedback
Body
I don't think I've seen this anywhere else, so please point me in the right direction if I missed it.
Scenario: you have permissions to bypass branching rules for the
master
branch. On themaster
branch, you make a local change and push to the remote. Currently, you get a message saying something like:Bypassed rule violations for refs/heads/master: Changes must be made through a pull request
. Your changes are applied.I like that you get a message. It would be great to take it a step further and ask for permission before bypassing rules. Using the example above, after the
git push
command, a response likeYou will bypass the following rules: ... Are you sure you want to continue?
would be great.As far as I'm aware, the branch protection rules are not something that can be pulled from the remote. If that were the case, it would be reasonable to build this into IDEs or as a git hook.
Beta Was this translation helpful? Give feedback.
All reactions