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
git switch feature/loginMake sure you are on your feature branch.
git fetch originGets the newest commits from the remote without changing your files.
git rebase origin/mainReplays your commits on top of the latest main. Conflicts? See the guide on rebase conflicts.
git push --force-with-lease --force-if-includesOnly if you had pushed the branch before. Ignore Git's hint to pull here: it would mix the old copies back in.
--force-if-includesstill stops if a teammate pushed to the branch in the meantime.Rewrites pushed history
feature/login is an example. Replace it with your own.
git switch feature/loginMake sure you are on your feature branch.
git fetch originGets the newest commits from the remote without changing your files.
git merge origin/mainMerges main's new commits into your branch with one merge commit. Safe on shared branches.
feature/login is an example. Replace it with your own.
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.