debuggitModeratepending
Debug: Git push rejected non-fast-forward
Viewed 0 times
non-fast-forwardrejectedpushforce-with-leaserebasepull
Error Messages
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:
git pull --rebase origin main
# Resolves conflicts if any
git push
git pull origin main # Creates merge commit
git push
git push --force-with-lease
# Safer than --force: fails if remote has unexpected commits
git push --force-with-lease origin feature-branch
# This rewrites shared history and breaks everyone's work
- Pull before starting work
- Use short-lived feature branches
- Set git config push.autoSetupRemote true
- Consider branch protection rules
- Safe approach - rebase your changes on top:
git pull --rebase origin main
# Resolves conflicts if any
git push
- Merge approach:
git pull origin main # Creates merge commit
git push
- If it's YOUR branch and nobody else uses it:
git push --force-with-lease
# Safer than --force: fails if remote has unexpected commits
- If you rebased and need to force push YOUR feature branch:
git push --force-with-lease origin feature-branch
- NEVER force push to main/master:
# This rewrites shared history and breaks everyone's work
- 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.