GIT
Git Merge
Merge branches
Git Merge
Merging is Git's way of putting a forked history back together. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch.
Merge a Branch
To merge a branch into your current branch:
# Switch to the branch you want to merge into (usually main)
git checkout main
# Merge the feature branch
git merge feature-branch
Fast-Forward Merge
If the branch you're merging hasn't diverged, Git will perform a fast-forward merge:
git merge feature-branch
# Fast-forward
Merge Commit
If branches have diverged, Git creates a merge commit:
git merge feature-branch
# Creates a merge commit
Resolve Merge Conflicts
If there are conflicts, Git will mark them in the files. You need to:
- Open the conflicted files
- Resolve the conflicts manually
- Stage the resolved files:
git add . - Complete the merge:
git commit
Abort a Merge
If you want to cancel a merge:
git merge --abort
Note: Always make sure you're on the correct branch before merging. Typically, you merge feature branches into main or master.