This error occurs when you try to push or merge changes to a protected branch that requires approval from designated code owners. The branch protection rules enforce that any pull request modifying code owned by specific individuals or teams must be approved by those code owners before merging.
The "GH006: Code owners review required" error indicates that GitHub's branch protection rules are blocking your push or merge operation. This happens when the target branch has the "Require review from Code Owners" protection rule enabled, and your changes affect files that have designated code owners who haven't approved the changes yet. Code owners are defined in a CODEOWNERS file within the repository, which specifies which users or teams are responsible for reviewing changes to specific files or directories. When you modify files covered by the CODEOWNERS file, GitHub automatically requests reviews from the designated owners. This protection mechanism ensures that changes to critical parts of the codebase are reviewed by the people most familiar with that code before being merged. It's a common practice in enterprise environments and open-source projects to maintain code quality and security. The error typically appears when: - **Pushing directly to a protected branch**: You're trying to push commits directly instead of using a pull request - **Merging without required approvals**: The pull request hasn't received approval from the designated code owners - **Force pushing to a protected branch**: Even with write access, force pushes may be blocked without code owner approval
Protected branches with code owner requirements don't accept direct pushes. You must use the pull request workflow:
# Create a new branch for your changes
git checkout -b feature/my-changes
# Make your changes and commit
git add .
git commit -m "Your descriptive commit message"
# Push the feature branch
git push -u origin feature/my-changesThen go to GitHub and create a pull request from your feature branch to the protected branch. GitHub will automatically request reviews from the appropriate code owners based on the CODEOWNERS file.
Check your pull request to see who needs to approve the changes:
1. Open your pull request on GitHub
2. Look at the "Reviewers" section in the sidebar
3. GitHub shows which code owners are required and their review status
4. The CODEOWNERS file determines who owns which files
To view the CODEOWNERS file:
# CODEOWNERS is typically in one of these locations:
cat .github/CODEOWNERS
cat CODEOWNERS
cat docs/CODEOWNERSExample CODEOWNERS syntax:
# Global owners (review everything)
* @default-reviewer
# Specific directory ownership
/src/api/ @backend-team
/src/frontend/ @frontend-team
# Specific file ownership
/security/ @security-team @lead-developerUnderstanding the CODEOWNERS file helps you identify who to contact for approval.
Once you've identified the required reviewers, request their review:
Via GitHub web interface:
1. Open your pull request
2. Click on "Reviewers" in the right sidebar
3. If code owners aren't already added, add them manually
4. Click "Request" next to their name
Via GitHub CLI:
# Request review from a specific user
gh pr edit --add-reviewer @username
# Request review from a team
gh pr edit --add-reviewer @org/team-name
# View current PR status
gh pr statusVia email or chat:
If the review is urgent, contact the code owners directly through your team's communication channels. Include:
- Link to the pull request
- Summary of changes
- Why the changes are needed
- Any urgency or deadline
If a code owner has requested changes, you need to address their feedback:
View requested changes:
1. Go to the pull request "Files changed" tab
2. Look for comments with "Changes requested"
3. Address each concern with new commits
Update your branch:
# Make the requested changes locally
git add .
git commit -m "Address code review feedback"
git push origin feature/my-changesRequest re-review:
After pushing your updates, the code owner needs to re-review. You can request a re-review:
1. Go to the PR's "Reviewers" section
2. Click the refresh icon next to the reviewer who requested changes
3. This notifies them that you've addressed their feedback
Important: Approval from *any one* of the listed code owners for a given path is typically sufficient, not all of them. Check your repository's branch protection settings for specific requirements.
If the designated code owner is unavailable (vacation, left the company, etc.), you have several options:
Option 1: Dismiss the stale review (requires admin access)
Repository admins can dismiss reviews:
1. Go to the pull request
2. Click on the review that's blocking
3. Click "Dismiss review"
4. Provide a reason for dismissal
Option 2: Contact a repository admin
Ask a repository administrator to:
- Dismiss the pending review
- Temporarily modify branch protection rules
- Add an alternative reviewer
Option 3: Update the CODEOWNERS file
If the code owner has permanently left, update the CODEOWNERS file:
# Edit the CODEOWNERS file
vim .github/CODEOWNERS
# Replace @old-user with @new-user
# Then create a PR for this change (may need admin approval)Option 4: Use bypass permissions
Some users may have "Allow specified actors to bypass required pull requests" permission in branch protection settings. Check with your repository admin.
If you have admin access, you can review and modify branch protection settings:
View branch protection rules:
1. Go to repository Settings
2. Click "Branches" in the left sidebar
3. Find your protected branch and click "Edit"
Relevant settings:
- Require a pull request before merging: Prevents direct pushes
- Require review from Code Owners: The setting causing this error
- Required number of approvals: How many approvals needed
- Dismiss stale pull request approvals when new commits are pushed: Whether new commits require re-review
- Allow specified actors to bypass required pull requests: Users/teams who can bypass
To add bypass permissions:
1. In branch protection rules, find "Allow specified actors to bypass required pull requests"
2. Add specific users, teams, or apps that should have bypass ability
3. Use sparingly and only for trusted automation or leads
Note: Changing these settings requires admin permissions and should align with your team's security policies.
If this error occurs in CI/CD pipelines, you need to ensure the workflow respects code owner requirements:
For GitHub Actions:
# Don't try to push directly to protected branches
# Instead, create a PR
name: Create Pull Request
on:
push:
branches:
- feature/*
jobs:
create-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
branch: automated-changes
title: "Automated: Update from CI"
reviewers: "@org/code-owners-team"For automation that needs to bypass:
1. Create a GitHub App or machine user with bypass permissions
2. Add that actor to "Allow specified actors to bypass required pull requests"
3. Use a Personal Access Token (PAT) with appropriate scopes
# Use a PAT with repo scope for the bypass user
git remote set-url origin https://x-access-token:${BYPASS_TOKEN}@github.com/org/repo.git
git push origin mainWarning: Bypassing code owner requirements in automation should be carefully considered. It's usually better to have automation create PRs that still require human approval.
Understanding GitHub's Code Owner System:
The CODEOWNERS file uses gitignore-style patterns to match files and assign owners. Key rules:
1. Pattern matching: Uses the same rules as .gitignore (with some exceptions)
2. Last match wins: If multiple patterns match a file, the last pattern's owners are used
3. File location priority: GitHub checks .github/CODEOWNERS, then CODEOWNERS, then docs/CODEOWNERS
4. File size limit: CODEOWNERS files are limited to 3 MB
CODEOWNERS Syntax Examples:
# Comment line
* @global-owner # Default owner for all files
# Directory patterns
/docs/ @docs-team # /docs directory only
docs/ @docs-team # docs directory anywhere in repo
/src/api/** @api-team # Recursive match
# File patterns
*.js @js-team # All .js files
/src/*.ts @typescript-lead # .ts files in /src only
# Multiple owners (any one can approve)
/security/ @security-team @cto
# Team syntax
/frontend/ @org/frontend-teamBranch Protection and Rulesets:
GitHub offers two systems for branch protection:
1. Classic Branch Protection: Settings per branch
2. Repository Rulesets (newer): More flexible, can target multiple branches with patterns
As of 2025, GitHub recommends using Rulesets for new configurations, though both work with CODEOWNERS.
Code Owner Approval Behavior:
- Only one code owner from a pattern needs to approve, not all
- If a PR touches files matching multiple patterns, an owner from each pattern must approve
- Code owners must have at least write access to the repository
- Draft PRs don't automatically request code owner reviews
Common Misconceptions:
1. "All listed owners must approve": False. Any one owner per file pattern is sufficient
2. "Code owners can be anyone": False. They must have write access
3. "CODEOWNERS applies to all branches": Each branch can have its own CODEOWNERS file
Troubleshooting CODEOWNERS:
# Validate CODEOWNERS syntax on GitHub
# Go to: Settings > Branches > Branch protection rules
# Look for "CODEOWNERS file" validation warnings
# Test which owners match a file
# Use GitHub's "About code owners" page on any file:
# Click a file > three dots menu > "View code owners"Security Considerations:
- Always protect the CODEOWNERS file itself: /.github/CODEOWNERS @security-team
- Regularly audit who has bypass permissions
- Use team reviews rather than individuals for bus-factor resilience
- Consider requiring multiple approvals for sensitive directories
Enterprise Features:
GitHub Enterprise offers additional capabilities:
- Required status checks integration with code owners
- Audit logs for code owner review bypasses
- SAML/SSO integration for code owner teams
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git