# fatal: cannot update ref 'refs/heads/main': trying to write non-commit object to branch 'main'

- **ID:** `git/fatal-override-branch-restriction`
- **Domain:** git
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A commit or update operation is attempting to write a non-commit object (like a tree or blob) directly to a branch reference, which violates Git's object model.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| git 2.35.0 | active | — | — |
| git 2.40.0 | active | — | — |
| git 2.44.0 | active | — | — |

## Workarounds

1. **git reflog --all | grep <commit-hash>  # Find the correct commit object, then use git branch -f main <correct-commit> to reset the branch to a valid commit** (75% success)
   ```
   git reflog --all | grep <commit-hash>  # Find the correct commit object, then use git branch -f main <correct-commit> to reset the branch to a valid commit
   ```
2. **git update-ref -m 'reset to valid commit' refs/heads/main <valid-commit-hash>  # Directly update the ref to a known good commit from reflog or backup** (80% success)
   ```
   git update-ref -m 'reset to valid commit' refs/heads/main <valid-commit-hash>  # Directly update the ref to a known good commit from reflog or backup
   ```

## Dead Ends

- **** — Running git fsck and then git gc without understanding the corruption source can remove necessary objects and worsen the repository state. (50% fail)
- **** — Using git update-ref -d to delete the branch reference entirely loses all commits on that branch, which is irreversible unless you have a backup. (90% fail)
