Git:RejectedNonFastForward
lastmod 2025-02-14created 2014-03-057 edits
Describes how to fix rejected errors when using the git push command.
Applies when an error message like the following occurs.
To ssh://[email protected]:8022/Users/yourname/Repository/balrocon2.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'ssh://[email protected]:8022/Users/yourname/Repository/balrocon2.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Question
I'm trying to push my project (all files in a new repository). I follow the steps but when I push with git push -u origin master I get this error:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:asantoya/projectnewbies.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
really many times I got this error and can't figure out what to do.
Answer
As the error message says: git pull before you try to git push. Apparently your local branch is out of sync with your tracking branch.
Depending on project rules and your workflow you might also want to use git pull --rebase.
Another Answer
Try this: git push -f origin master
For reference, I solved it this way (with the --force option) when applying a moved master branch to the remote repository after moving the master branch.