Merge the main branch into a feature branch
Updated August 29, 2026
To bring the latest main branch into a feature branch, fetch first and merge the remote-tracking branch:
git fetch origin
git switch feature/my-change
git merge origin/main
If the repository really uses master, replace main with master. Check git branch -vv and the hosting service rather than guessing the default branch name. Resolve conflicts in the marked files, stage the resolved files, and finish with git commit; use git merge --abort if you need to return to the pre-merge state.
Run the project's tests and inspect git diff origin/main...HEAD before pushing. A rebase onto origin/main creates a linear history but rewrites the feature branch's commits, so coordinate before rebasing a branch others use. Merging does not automatically make application behavior compatible; review migrations, lockfiles, and generated files like any other change.
Sources
related.
Ruslan Osipov
About the author