Interview Prep/Git & GitHub/Conflicts, remotes, fetch, pull and push

Why was my push rejected with "non-fast-forward" or "fetch first"?

IntermediateConceptConflicts, remotes, fetch, pull and push
Answer

The remote branch has commits you do not have, so updating it would discard them. Fetch, then integrate with merge or rebase and push again. Force-pushing is only right for your own feature branch, and then only with lease.

! [rejected] main -> main (fetch first)
hint: Updates were rejected because the remote contains work that you do not have locally.
All Git & GitHub questions Roadmap: Git & GitHub

More on Conflicts, remotes, fetch, pull and push