You pushed and Git refused. The remote branch has commits that your copy does not have, usually because someone else (or you, from another machine) pushed first. Git will not overwrite them.
The remote branch moved on. Your push would drop their commits, so Git says no.
git pull brings their commits in (and may ask for a merge message). Then git push.
Do not reach for git push --force. It can wipe out your teammate's work.
"fetch first" and "non-fast-forward" are the same problem. Git says "fetch first" when it has not yet seen the remote commits, and "non-fast-forward" once you have fetched them.
you@laptop my-project % git push origin main
To github.com:you/my-project.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'github.com:you/my-project.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Real Git prints the second line with your own remote URL. The hint wording comes from Git itself; the older wording is shown on the GitHub Docs page on non-fast-forward errors.
git pull then git pushgit fetch then git log --oneline main..origin/maingit pull --rebase then git pushgit push --force-with-lease--force does not check.After git pull, run git status. It should say your branch is ahead by your commits. Then git push shows a line like main -> main without "rejected". If the pull stopped on a conflict, fix that first.
fatal: refusing to merge unrelated historiesThe two histories share no commitThis usually means a different repo was added as the remote. Check git remote -v first. See remote origin.fatal: Authentication failedSign-in problem, not a history problemSee the authentication fix.Git could not update the remote branch with your commits. Here the reason is the line above it: [rejected], because the remote has commits you do not.
Same cause. fetch first appears when your copy has not seen the remote commits. non-fast-forward appears after you fetched and your branch is behind.
Not as a first move. It replaces the remote branch with yours and can delete other people's commits. Pull first. If you must, use --force-with-lease on your own branch.
No. It merges the remote commits with your committed work. Uncommitted edits can block it, so commit or stash them first.