All fixes

Help, I need the latest main in my feature branch

main moved on while you worked. Bring its new commits into your branch with a rebase or a merge.

The fix

  1. git switch feature/login

    Make sure you are on your feature branch.

  2. git fetch origin

    Gets the newest commits from the remote without changing your files.

  3. git rebase origin/main

    Replays your commits on top of the latest main. Conflicts? See the guide on rebase conflicts.

  4. git push --force-with-lease --force-if-includes

    Only if you had pushed the branch before. Ignore Git's hint to pull here: it would mix the old copies back in. --force-if-includes still stops if a teammate pushed to the branch in the meantime.

    Rewrites pushed history

feature/login is an example. Replace it with your own.

What happens to your history
BeforeABDCorigin/mainHEADfeature/login
AfterABDC′origin/mainHEADfeature/login

Why this works

Both ways end with your branch containing everything from main. A rebase replays your commits on top of the newest main, which gives a straight history but creates new commits, so a branch you already pushed needs a force push. A merge adds one merge commit and rewrites nothing, which is the safe choice when others work on the same branch.