You tried to push your changes and git slapped you with this:

!ehhrii[rnnrotter::j:eUicfpttadseiadltr]eeedsmotwtoeerpecuosrumhenajtiseenocrmtpeeadrrtmeb.afeiscnatu(osneonot-rhfieagsittni-'pfoorfwayrodu)rcurrentbranchisbehind

This is one of the most common git errors, and it’s actually git protecting you from accidentally overwriting someone else’s work (or your own work from another machine).

Why This Happens

The remote branch has commits that your local branch doesn’t have. This typically occurs when:

  1. Someone else pushed changes to the same branch
  2. You pushed from another machine and forgot to pull
  3. You rebased or amended commits that were already pushed
  4. A CI/CD pipeline made commits (version bumps, changelog updates)

The Safe Fix: Pull First

In most cases, this is what you want:

1
2
git pull --rebase origin main
git push origin main

The --rebase flag replays your local commits on top of the remote changes, keeping a clean linear history.

If you prefer merge commits:

1
2
git pull origin main
git push origin main

Handling Conflicts

If the pull results in conflicts, git will pause and let you resolve them:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# See which files have conflicts
git status

# Edit the conflicted files, then:
git add <resolved-files>
git rebase --continue

# Or if you used merge:
git add <resolved-files>
git commit

The Nuclear Option: Force Push

⚠️ Warning: Only do this if you’re absolutely sure you want to overwrite the remote branch.

1
git push --force origin main

This is appropriate when:

  • You intentionally rebased/squashed commits
  • You’re the only one working on the branch
  • You need to undo a bad push

Safer Force Push

Use --force-with-lease instead of --force:

1
git push --force-with-lease origin main

This fails if someone else pushed changes since your last fetch, preventing you from accidentally overwriting their work.

Checking What’s Different

Before deciding how to fix it, see what’s actually different:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Fetch remote changes without merging
git fetch origin

# See commits on remote that you don't have
git log HEAD..origin/main --oneline

# See commits you have that remote doesn't
git log origin/main..HEAD --oneline

# See both
git log --oneline --left-right HEAD...origin/main

Common Scenarios

Scenario 1: CI Made a Commit

Your pipeline updated a version file or changelog:

1
2
git pull --rebase origin main
git push

Scenario 2: You Amended a Pushed Commit

You ran git commit --amend on a commit that was already pushed:

1
2
# If you're sure no one else pulled the old commit:
git push --force-with-lease origin main

Scenario 3: You Rebased a Shared Branch

You rebased main and now can’t push:

1
2
3
# If others are working on this branch, coordinate first!
# Then:
git push --force-with-lease origin main

Everyone else will need to:

1
2
3
git fetch origin
git reset --hard origin/main
# Their unpushed work is now lost - make sure they push first!

Scenario 4: Diverged History

Your branch and remote have both moved forward:

1
2
3
4
5
6
7
# Option A: Rebase your changes on top
git pull --rebase origin main
git push

# Option B: Merge (creates a merge commit)
git pull origin main
git push

Prevention

  1. Always pull before starting work: git pull --rebase
  2. Push frequently: Don’t let commits pile up locally
  3. Use feature branches: Avoid pushing directly to main
  4. Set up pull rebase by default:
1
git config --global pull.rebase true

Quick Reference

SituationCommand
Safe fix (rebase)git pull --rebase origin main && git push
Safe fix (merge)git pull origin main && git push
Force push (careful!)git push --force-with-lease origin main
See differencegit fetch && git log --oneline --left-right HEAD...origin/main

The non-fast-forward error is git being helpful, not git being broken. Take a moment to understand what diverged before choosing your fix.