Update my feature branch with the latest main
When to use this: You are working on a branch and main has moved on. Bring main's changes into your branch before you finish.
Before you start
Steps
-
Update your local main
terminalgit switch main git pullGet GitHub's latest
mainonto your PC first. -
Go back to your branch
terminalgit switch my-branchReplace
my-branchwith your branch name. -
Merge main into it
terminalgit merge mainBrings everything that is new on
maininto your branch. If Git saysAlready up to date, nothing to do. ACONFLICTmessage means you must resolve it. -
Run the site and test
terminalnpm run buildCheck the combination works before pushing.
-
Push your updated branch
terminalgit pushIf the branch was never pushed, Git tells you to use
git push -u origin my-branch. A Vercel preview deploy is created for the branch.
How to verify it worked
git log --oneline --graph -n 10shows main's commits inside your branch history.git statusis clean and the preview deployment builds.
How to undo it
Merge not pushed yet and you want to cancel it:
git reset --hard ORIG_HEADMerge stopped on conflicts and you want to give up:
git merge --abortCommon errors and fixes
CONFLICT during merge Follow the merge-conflict scenario, then git commit to finish the merge. error: Your local changes would be overwritten Commit or stash before switching/merging. Q&A
Why merge main into my branch rather than the other way around?
It lets you fix conflicts and test on your branch, where nothing is live yet, so main stays clean and deployable.
Can I merge origin/main directly without updating local main?
Yes: git fetch then git merge origin/main on your branch. It does the same job in fewer steps.