Branching and Merging#
Basic Merging#
git switch <parent-branch> && git merge <child-branch>- Fast-forward: If the parent branch has not moved, Git simply moves the pointer forward.
git switch <child-branch> && git merge <parent-branch>- Results in “Already up to date” if the parent is already an ancestor.
3-way Merge#
When two branches have diverged, Git performs a 3-way merge using:
- Common ancestor
- Current branch (Target)
- Source branch
Squash Merge#
git merge --squash <branch>- Condenses all commits from the source branch into exactly one new commit on the destination branch.
- Unlike a default merge which creates a merge commit with multiple parents to preserve history, a squash merge results in a linear and clean history.
- It does not create a commit automatically. You must manually run
git committo finalize the process.