Skip to content

Git:RejectedNonFastForward

git push명령어를 사용할 경우 rejected 관련 에러가 발생될 경우 해결방법에 대하여 설명한다.

아래와 같은 에러 메세지가 발생될 경우에 해당된다.

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

참고로, master branch를 옮긴 후 Remote 저장소에 옮긴 master branch를 적용할 경우 이 방법(--force옵션 적용)으로 해결하였다.

Favorite site