! [rejected] master -> master (non-fast-forward) – Git Error

Total
0
Shares

! [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