Merging Branches Back
Merging
When a feature is done, you merge it back into main. You merge into the branch you're currently on.
$ git switch main
$ git merge feature-login
Updating 9f8e7d6..a1b2c3d
Fast-forward
login.js | 20 ++++++++++
Two kinds of merge:
| Type | When | Result |
|---|---|---|
| Fast-forward | main hasn't moved since you branched | Pointer just moves forward, no merge commit |
| Three-way merge | Both branches have new commits | Creates a merge commit joining the histories |
Tip: The typical flow:git switch main→git pull(get latest) →git merge feature. Always merge into the target branch while standing on it.
After merging, clean up: git branch -d feature-login.