Home/Engineer/Troubleshooting/Completely Fix git push reje…
TroubleshootingBeginnerUbuntuDebianmacOSWindowsGitpush rejectednon-fast-forward

Completely Fix git push rejected — non-fast-forward · protected branch · pre-receive hook

A guide to identifying the cause of each git push failure type—Updates were rejected, remote rejected, pre-receive hook declined, and more—and resolving it safely.

Contents
  1. Quick lookup by error type
  2. Cause 1 — non-fast-forward (most common)
  3. Cause 2 — GitHub Protected Branch
  4. Cause 3 — Remote branch name does not match the current branch
  5. Cause 4 — The remote repository is not bare
  6. Cause 5 — A large file is included
  7. Summary
  8. When rejected with protected branch / hook declined

You can pinpoint the cause from the message shown when git push is rejected.


Quick lookup by error type

Error messageCause
Updates were rejected because the remote contains workThe remote has commits that your local branch does not
Updates were rejected because the tip of your current branch is behindYour local branch is behind the remote
remote: error: GH006: Protected branch update failedGitHub protected branch
remote rejected ... pre-receive hook declinedServer hook or protection rule

Cause 1 — non-fast-forward (most common)

Your push conflicts because someone else has already pushed commits to the remote.

Bash
# Check remote state
git fetch origin
git log --oneline HEAD..origin/main   # Commits that exist only on the remote
git log --oneline origin/main..HEAD   # Commits that exist only in your local repo
Bash
git fetch origin
git rebase origin/main

# If there are no conflicts, you can push immediately
git push origin main

If a conflict occurs:

Bash
# After fixing conflicted files
git add conflicted-file
git rebase --continue

# Abort and roll back
git rebase --abort

Method B: merge

Bash
git fetch origin
git merge origin/main
git push origin main

Method C: pull --rebase (all in one)

Bash
git pull --rebase origin main
git push origin main

Cause 2 — GitHub Protected Branch

Bash
# Example error
# remote: error: GH006: Protected branch update failed
# remote: error: Required status check "CI" is failing.

Direct pushes are blocked. How to resolve:

  1. Merge via Pull Request (the proper way)
  2. Disable protection in GitHub settings (admin access required)
    • Repository → Settings → Branches → Branch protection rules

Bypassing with a force push risks wiping other people's commits in a team workflow. Use a PR instead.


Cause 3 — Remote branch name does not match the current branch

Bash
# Check the current branch
git branch

# List remote branches
git branch -r

# Push with an explicit branch mapping
git push origin local-branch:remote-branch

# Example: feature/login → feature/login on origin
git push origin feature/login

Cause 4 — The remote repository is not bare

On a self-hosted git server, push is rejected if the remote branch is currently checked out.

Bash
# Run on the remote server
git config --bool receive.denyCurrentBranch false

# Or set receive.denyCurrentBranch to updateInstead
git config receive.denyCurrentBranch updateInstead

Cause 5 — A large file is included

Bash
# Example error
# remote: error: File bigfile.zip is 120.00 MB; this exceeds GitHub's file size limit of 100.00 MB

# Remove the file from that commit
git log --oneline -5
git show --stat HEAD | grep large-file

# Remove only the file from the last commit
git rm --cached large-file.zip
echo "large-file.zip" >> .gitignore
git commit --amend --no-edit

For large files, use Git LFS:

Bash
git lfs install
git lfs track "*.zip"
git add .gitattributes

Summary

SituationFix
New commits on the remotegit pull --rebase then push
Protected branchCreate a PR
Branch name mismatchExplicitly git push origin local:remote
Large filegit rm --cached then amend

When rejected with protected branch / hook declined

! [remote rejected] ... (protected branch hook declined) means the remote repository (GitHub, etc.) branch protection rules blocked a direct push. Unlike non-fast-forward, this is not fixed by git pull --rebase.

  • No direct push to main/master rule → create a new branch and merge via Pull Request.
  • Required reviews or status checks not met → merge after review approval and CI passing.
  • In an emergency, a repo admin can temporarily adjust the protection rules under Settings → Branches (not recommended).
#Git#push rejected#non-fast-forward#protected branch#Troubleshooting#rebase#merge
Editorial note

AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us

Topic-related official docs (auto-linked · not per-claim sources)Git documentation ↗

Questions & answers

Ask a question about this guide. We'll review and reply.