This error is faced when git cannot commit your changes to the remote repository. This may happen because your commit was lost or if someone else is trying to push to the same branch as you. This is the error you face.
$ git push origin master
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/USERNAME/REPOSITORY.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 detail
This can be fixed by fetching and merging the changes made on the remote branch with the changes that you have made locally. Run the following commands to fetch and merge.
$ git fetch origin
This command fetches the updates made to a remote repository.
$ git merge origin YOUR_BRANCH_NAME
This command merges the updates made online with your local work.