Merging a branch back in
When your feature branch is ready, you merge it into main.
First switch to the branch you want to merge into (usually main), then
merge the feature branch.
Merge feature into main
$ git switch main
$ git merge feature-login - Switch to main (status-bar branch picker)
- Open Command Palette → Git: Merge Branch…
- Pick the branch to merge in
Order matters: you stand on the destination branch and pull the other one in.
Fast-forward vs merge commit
If main hasn't changed since you branched, Git just slides main
forward to catch up — a fast-forward, no extra commit. If both branches
moved on, Git creates a merge commit that has two parents, joining the two
histories. Both are normal.
Merge vs rebase — the short version
- Merge keeps both histories exactly as they happened and adds a merge commit to join them. Honest and safe — great default for beginners.
- Rebase rewrites your branch's commits so they appear to start from the latest
main, giving a clean, straight line. Tidier history, but it rewrites commits.
Rebase your feature onto the latest main
$ git switch feature-login
$ git rebase main - Open Command Palette → Git: Rebase Branch…
- Choose main as the base
Golden rule: never rebase commits you've already pushed and shared, unless you really know why — it rewrites history others may depend on.
When in doubt, merge. It's the safe choice and you can always learn rebase later. Many teams happily use merge forever.
Hit a conflict? Two branches changed the same lines and Git paused to ask which to keep. It's a question, not an error — Fix Merge Conflicts walks through reading the markers, VS Code's Merge Editor, and the git merge --abort escape hatch.
After a successful merge
With the feature merged into main, delete the branch to keep things tidy — the
work is safely in main's history now.
Clean up the merged branch
$ git branch -d feature-login
$ git push origin --delete feature-login # if it was also pushed to GitHub - Delete locally from the branch picker; on GitHub, the PR page shows a 'Delete branch' button after merging
Two handy extras: after staging resolved files you can finish a conflicted merge with git merge --continue (same effect as committing). And git pull --rebase updates your branch without adding a merge commit, for a cleaner straight line.
Up next: the moment every beginner dreads and shouldn't — a merge conflict, handled calmly in the Merge Editor.