--- sidebar_position: 4 description: "Protect branches" --- # gt branch protect Protect branches ## Synopsis ```text Add a protection rule for each existing branch, or with --pattern for every branch matching a glob. By default nobody can push directly and pull requests need one approving review. When a branch or pattern has a rule already, change only the settings the flags name and keep the others; --allow-push replaces those who may push directly. ``` ``` gt branch protect ... [flags] ``` ## Examples ``` # Require two approvals and passing CI on main $ gt branch protect main --required-approvals 2 --status-check ci/build # Let the release team push to every release branch $ gt branch protect --pattern 'release/*' --allow-push acme/release ``` ## Options ``` --allow-push strings Users, or teams as ORG/TEAM, that may push directly --block-on-rejected-reviews Block merging while changes are requested --dismiss-stale-approvals Dismiss approvals when new commits are pushed -h, --help help for protect --pattern string Protect the branches matching this glob, such as release/* --required-approvals int Approving reviews that pull requests need (default 1) --status-check strings Status checks that must pass (repeatable) ``` ## Options inherited from parent commands ``` --cwd directory Working directory for repository discovery --debug Log the method, URL, status, and duration of each HTTP request to stderr --host URL Gitea instance URL, including any base path --interactive Allow prompts with machine output -q, --jq expression Filter JSON output using a jq expression; implies --json --json fields[="*"] Output JSON with the specified comma-separated fields, or all fields --no-input Disable prompts and implicit editor/browser interactions --remote remote Git remote used for repository discovery -R, --repo OWNER/REPO Select a repository as OWNER/REPO or URL --sudo user Perform API requests as this user (requires an administrator account) --user name Account name on the selected instance -y, --yes Accept confirmations without prompting ``` ## SEE ALSO * [gt branch](../branch/index.md): Manage remote branches and protection rules