Video in progress
You ran `git push` and got "rejected, non-fast-forward". What does it mean and what do you do?
The branch on the server has commits you do not have: someone pushed before you. First you bring them in (git pull or git pull --rebase), resolve any conflict, and then push again.
📖 Answer
Git is protecting you from wiping out the history on the server. The history you are trying to push is not a continuation of the one on the server.
git pull --rebase origin main # puts your commits on top of the server's
# if there is a conflict: fix the files, git add, git rebase --continue
git push origin main
What not to do: see the error and immediately run git push --force. That deletes your colleague's commits from the server. On a shared branch (main, develop) that is almost always a mistake.
In daily work this rarely happens if everyone works on their own feature branch and merges into main through a PR.
Sign up to mark studied questions and save your progress.