Merging Basics
Merging brings changes from one branch into another. When you've finished a feature on a separate branch, you merge it into main to make those changes part of your primary codebase. Git handles most merges automatically, combining the work intelligently.
The Merge Workflow
First, switch to the branch you want to merge into — usually main:
Then merge the feature branch:
Git combines the changes from feature-login into main. Your feature is now part of the main codebase.
Fast-Forward Merges
When your feature branch has commits that main doesn't have, and main hasn't changed since you branched, Git performs a "fast-forward" merge. It simply moves main forward to include your new commits. No extra merge commit is needed.
This is the simplest kind of merge — Git just updates which commit main points to.
Merge Commits
If both branches have new commits since they diverged, Git creates a "merge commit" that combines them. This commit has two parents — one from each branch — and represents the point where the work came together.
git merge feature-login
# Merge made by the 'ort' strategy.
The merge commit appears in your history, showing when and where branches were combined.
When Conflicts Happen
Sometimes Git can't automatically combine changes — usually when both branches modified the same lines in the same file. This is called a merge conflict.
Don't panic — conflicts are normal. Git marks the conflicting sections in your files, and you decide how to resolve them. We'll cover this in detail in the next lesson.
After Merging
Once merged, you can delete the feature branch if you're done with it:
git branch -d feature-login
The -d flag deletes the branch. Your commits are safe — they're now part of main.