All fixes

Help, I had my push rejected

Someone pushed before you did. Put your commits on top of theirs and push again, without force.

What Git says~/my-app
git push
To https://github.com/ada/my-app.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/ada/my-app.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

The fix

  1. git pull --rebase

    Fetches your teammates' commits and puts yours on top. Conflicts? Resolve them like in a rebase.

  2. git push

    Goes through now.

Does the message say non-fast-forward right after you amended or rebased commits you had pushed? Then pulling would undo your rewrite. Use git push --force-with-lease on your own branch instead.

What happens to your history
BeforeABCDHEADmainorigin/main
AfterABDC′HEADmainorigin/main

Why this works

Git only accepts a push that builds on what the remote already has. A teammate's new commits are missing from your branch, so your push would erase them, and Git says no. pull --rebase fetches their commits and replays yours on top, after which your push is a simple step forward. Got uncommitted changes? Add --autostash.