Branch Protection Bypass Attempt — Fix (2026)
The Error
remote: error: GH006: Protected branch update failed for refs/heads/main
remote: error: Required status checks are missing: ci/tests, code-review
Claude Code attempted to push directly to 'main' — branch protection rules
require pull request reviews and passing CI checks.
This appears when Claude Code commits directly to main (or another protected branch) and tries to push, which GitHub’s branch protection rules reject.
The Fix
git checkout -b fix/auth-validation
git push -u origin fix/auth-validation
gh pr create --title "Fix auth validation" --body "Fixes the null check in auth handler"
- Create a feature branch from the current state.
- Push the feature branch to remote.
- Create a pull request to merge into main through the proper review process.
Why This Happens
Claude Code works on whatever branch is currently checked out. If you start a session on main and ask Claude to make changes, it commits to main locally. The push fails because GitHub branch protection requires pull requests, status checks, and/or code reviews. Claude Code does not check branch protection rules before committing because protection is enforced server-side.
If That Doesn’t Work
If you already committed to main locally and need to move the commit:
git branch fix/auth-validation
git reset --hard HEAD~1
git checkout fix/auth-validation
git push -u origin fix/auth-validation
If the branch requires signed commits:
git config commit.gpgsign true
git commit --amend --no-edit
git push -u origin fix/auth-validation
Check what protection rules are set:
gh api repos/:owner/:repo/branches/main/protection | jq '.required_status_checks'
Prevention
# CLAUDE.md rule
Never commit directly to main. Always create a feature branch first: 'git checkout -b fix/description'. Push feature branches and create PRs. Check current branch with 'git branch --show-current' before committing.
Related Error Messages
This fix also applies if you see these related error messages:
fatal: not a git repositoryerror: failed to push some refsfatal: refusing to merge unrelated historiesError reading configuration fileJSON parse error in config
Frequently Asked Questions
Why does Claude Code require git?
Claude Code uses git for several core operations: tracking file changes, creating commits, reading blame information, searching history with git log, and managing branches. Without git, these operations fail and Claude Code falls back to less efficient alternatives.
Can Claude Code work in a non-git directory?
Yes, but with reduced functionality. File search and editing work normally, but version control operations (commit, diff, blame) are unavailable. Claude Code displays a warning when opened in a directory without git initialization.
How do I prevent Claude Code from making unwanted git operations?
Add rules to your CLAUDE.md: Do not create commits automatically. Do not run git push. Always ask before any git operation that modifies history. Claude Code respects these constraints and asks for confirmation before proceeding.
Where does Claude Code store its configuration?
Configuration is stored in ~/.claude/config.json for global settings and .claude/config.json in the project root for project-specific settings. Project settings override global settings for any overlapping keys.
Related Guides
Try it: Paste your error into our Error Diagnostic for an instant fix.
- Terminal Emulator Rendering Artifacts — Fix (2026)
- How to Use Thirdweb SDK Workflow (2026)
- Python Virtualenv Not Activated — Fix (2026)
- Claude Code Offline Mode Setup (2026)
Git Operations in Claude Code: Safety Checklist
Claude Code can execute git commands, which makes safety guardrails important:
Before any destructive operation: Always check git status and git stash list to confirm there are no uncommitted changes that could be lost.
Branch management: Claude Code should create feature branches for non-trivial changes rather than committing directly to main. Use the pattern git checkout -b claude/feature-name to clearly identify AI-generated branches.
Commit message conventions: Configure your preferred commit format in CLAUDE.md. Claude Code follows the format you specify. Common formats: Conventional Commits (feat: add user search), Angular style, or simple descriptive messages.
Common Git Mistakes Claude Code Makes
-
Amending the wrong commit. If a pre-commit hook fails, Claude Code sometimes uses
--amendon the next attempt, which modifies the previous (successful) commit instead of creating a new one. Configure CLAUDE.md with: “Never use git commit –amend. Always create new commits.” -
Force pushing to shared branches. Claude Code may suggest
git push --forceto resolve push rejections. AddBash(git push --force*)to your deny list in settings.json. -
Committing generated files. Without guidance, Claude Code may commit
dist/,node_modules/, or.envfiles. Ensure your.gitignoreis complete and add a pre-commit hook that checks for these.