# git-branch-check **Repository Path**: thesadboy/git-branch-check ## Basic Information - **Project Name**: git-branch-check - **Description**: 用于检查当前git分支是否满足执行命令的条件,用在npm script hook上,防止在错误的分支执行了错误的命令 - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 0 - **Created**: 2020-08-19 - **Last Updated**: 2025-05-06 ## Categories & Tags **Categories**: vcs **Tags**: None ## README # git-branch-check > 用于检查当前git分支是否满足执行命令的条件,用在npm script hook上,防止在错误的分支执行了错误的命令 ## 安装 ```bash npm install git-branch-check -D yarn add git-branch-check -D ``` ## 使用 ```json //package.json { "name": "xxx", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "build": "node ./build.js", "prebuild": "npx git-branch-check include master", "staging": "node ./staging.js", "prestaging": "npx git-branch-check exclude master" }, "keywords": [], "author": "", "license": "MIT", "dependencies": { "colors": "^1.4.0", "commander": "^6.0.0", "execa": "^4.0.3" } } ``` 如上配置,`npm run build` 只能在`master`分支运行,其他分支运行则会报错,而`npm run staging` 则是只能在`master`分支之外的分支执行,`master`分支执行则会报错 ## 说明 ```bash Usage: git-branch-check [options] [command] Options: -V, --version output the version number -h, --help display help for command Commands: include 允许在限制的分支中执行,多个分支以","符号分割 exclude 允许在排除的分支中执行,多个分支以","符号分割 help [command] display help for command ```