🌿 BranchingCommonly used
How to merge a branch in Git
Integrate changes from one branch into another.
Merge a branch into current branch
git switch main
git merge feature-branchFirst switch to the target branch, then merge the source branch into it.
When to use: Standard merge for integrating a completed feature.
Merge without fast-forward
git merge --no-ff feature-branchCreates a merge commit even if a fast-forward is possible. Preserves branch history.
When to use: When you want a clear record of when a feature was merged.
Squash and merge
git merge --squash feature-branchCombines all commits from the feature branch into one staged change. You then commit it.
When to use: When you want the feature in one clean commit rather than all intermediate commits.
After this, run git commit -m "Feature: description" to create the single commit.
Abort a merge in progress
git merge --abortCancels a merge that has conflicts and returns to the pre-merge state.
When to use: When you want to back out of a merge that has conflicts.