Before you rebase a feature branch, your local main should be up to date. Switching to main, pulling and switching back is three commands and touches your working tree twice.
git fetch origin main:main
The part after the space is a refspec: take main from the remote and write it to your local main. Git only does that when it’s a fast-forward, so local commits on main are never thrown away. If main has diverged, you get ! [rejected] main -> main (non-fast-forward) and nothing changes.
Then rebase as usual:
git rebase main
I like that your working tree isn’t touched during the fetch, so editors and running dev servers don’t see files jumping around.
This doesn’t work for the branch you’re on. Git refuses with refusing to fetch into branch ... checked out, because updating it would leave your working tree out of sync. For the current branch, use git pull as normal. The same goes for a branch checked out in another worktree.
Never add a plus in front of the refspec here, as in +main:main. The plus forces the update even when it isn’t a fast-forward, and then any local commit on main that isn’t on the server is gone from the branch.
Further reading: git-fetch documentation