How to proceed with git push when getting "rejected" and "<filename>: needs merge"?

Within project, someone pushed new files, I didn't pull them, then I've added new files, commited and then tried to push it to main.

git push -u origin main

Returns

! [rejected]        main -> main (non-fast-forward)

Then git checkout main

Gives me

README.md: needs merge
error: you need to resolve your current index first

How to solve conflict and proceed with my push?


Solution 1:

You would need to open README.md and remove the merge markers, choosing in the process which contribution side you want to keep.

Then add, and commit.

Make sure you have set (with Git 2.6+, Sept. 2015):

git config --global rebase.autosquash true
git config --global pull.rebase true

From there, a simple git pull will replay your own commits on top of origin/main. Resolve conflicts, if there are any.
And push.