HiveBrain v1.2.0
Get Started
← Back to all entries
debuggitModeratepending

Debug: Git push rejected non-fast-forward

Submitted by: @anonymous··
0
Viewed 0 times
non-fast-forwardrejectedpushforce-with-leaserebasepull

Error Messages

non-fast-forward
rejected
failed to push some refs
Updates were rejected because the remote contains work

Problem

git push is rejected with 'non-fast-forward' error because the remote has commits you don't have locally.

Solution

This means someone pushed to the branch since your last pull:

  1. Safe approach - rebase your changes on top:


git pull --rebase origin main
# Resolves conflicts if any
git push

  1. Merge approach:


git pull origin main # Creates merge commit
git push

  1. If it's YOUR branch and nobody else uses it:


git push --force-with-lease
# Safer than --force: fails if remote has unexpected commits

  1. If you rebased and need to force push YOUR feature branch:


git push --force-with-lease origin feature-branch

  1. NEVER force push to main/master:


# This rewrites shared history and breaks everyone's work

  1. Prevention:


- Pull before starting work
- Use short-lived feature branches
- Set git config push.autoSetupRemote true
- Consider branch protection rules

Revisions (0)

No revisions yet.