🔧 Error Fixes

Fix: git — Your branch is behind 'origin/main'


Your branch is behind 'origin/main' by 3 commits, and can be fast-forwarded.

Your local branch is missing commits that exist on the remote. Someone pushed changes you don’t have yet.

Fix 1: Pull the changes

git pull

This fetches the remote changes and merges them into your branch. If you have no local changes, it’s a clean fast-forward.

Fix 2: Pull with rebase (cleaner history)

git pull --rebase

Instead of creating a merge commit, this replays your local commits on top of the remote changes. Cleaner history.

Fix 3: You’re on the wrong branch

# Check what branch you're on
git branch

# Switch to the right branch
git checkout main
git pull

Fix 4: You intentionally want to overwrite remote

If you rewrote history locally (rebase, amend) and want to force your version:

# ⚠️ Only if you know what you're doing
git push --force-with-lease

--force-with-lease is safer than --force — it fails if someone else pushed in the meantime.

Prevention

Pull before you start working:

git pull  # Always do this first
# ... make changes ...
git add -A && git commit -m "my changes"
git push

See also: Git cheat sheet | Git push rejected fix | Git merge conflict fix