! [rejected] master -> master (non-fast-forward) error indicates that in order to complete your commit request, git has to lose some previous commits. This is not good because it leads to the lost of work done by other peers.

The actual error snippet, looks like this –

$ git push origin main
> To https://github.com/superhero/ironman.git
>  ! [rejected]        main -> main (non-fast-forward)
> error: failed to push some refs to 'https://github.com/superhero/ironman.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.

The error is clear –

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.

Use these commands to solve this issue –

git fetch origin
git merge origin master

    Tweet this to help others

Tagged in:

Comments

About the Author

akamit

I am Akash Mittal, an overall computer scientist. If you want to guest post, need help in your projects, want to advertise, Feel free to contact me at [email protected]

View All Articles