CLI to check whether current Git branch is protected
npm install --global git-is-branch-protected-cli
gibp --help
Usage
gibp [options]
Options
--protected-branches, -b Specify protected branches [Default: master, main, develop]
--silent, -s Do not show any error messages
Examples
gibp -b "master, main, develop, another-important-branch"
gibp -b master
It's easy to forget setting up branch protection on GitHub, GitLab or any other Git hosting service, and before you know it, you've pushed to master
during your late night coding session. Or perhaps you have scripted automatic updates that will push and create pull requests to several repositories at once and want to ensure you're not pushing to the wrong branch?
This tool comes to the rescue and with the help of Git Hooks and husky prevents you from accidentally pushing to your remote master
, main
or develop
branch. All you need to do is install husky
and git-is-branch-protected-cli
to your project:
npm install husky git-is-branch-protected-cli --save-dev
and add the following to your package.json
to protect anyone from commiting to master
, main
, or develop
:
{
"husky": {
"hooks": {
"pre-push": "gibp"
}
}
}
you can also instruct gipb
to project other branches using the following configuration as an example:
{
"husky": {
"hooks": {
"pre-push": "gibp -b \"master, main, develop, foo-bar\""
}
}
}
After this setup, the pre-push
hook will fail if you are on a protected branch as gibp
returns exit code 1
, thereby preventing you from accidentally pushing to the wrong remote branch.
--no-verify
. Therefore, please also consider setting up server-side branch protection.
- git-is-branch-protected - API for this CLI.
- git-push-pr - Push and open pull request in your default browser.
MIT © Tobias Büschel