Update my feature branch with the latest main

careful intermediate #merge main#branch#update#sync

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.

Be careful with this one. Merging may produce conflicts. Resolve them on your branch, not on main.

Before you start

Steps

  1. Update your local main

    terminal
    git switch main
    git pull

    Get GitHub's latest main onto your PC first.

  2. Go back to your branch

    terminal
    git switch my-branch

    Replace my-branch with your branch name.

  3. Merge main into it

    terminal
    git merge main

    Brings everything that is new on main into your branch. If Git says Already up to date, nothing to do. A CONFLICT message means you must resolve it.

  4. Run the site and test

    terminal
    npm run build

    Check the combination works before pushing.

  5. Push your updated branch

    terminal
    git push

    If 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 10 shows main's commits inside your branch history.
  • git status is clean and the preview deployment builds.

How to undo it

Merge not pushed yet and you want to cancel it:

terminal
git reset --hard ORIG_HEAD

Merge stopped on conflicts and you want to give up:

terminal
git merge --abort

Common 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.

Practice these as flashcards →

Terms in this scenario

Related scenarios

My notes

Saved in this browser only.