Merge a branch
Branching · Article 4 of 9 · 2 min read
Merging brings the work from one branch into another.
The short version
git merge takes the commits from another branch and combines them into the branch you are on.
Details
If main has not moved since you branched, Git just moves the main name forward. This is a fast forward. If both branches have new commits, Git creates a merge commit with two parents.
Try it yourself
git switch main
git merge add-greeting
git log --oneline
git branch -d add-greeting
You should see the greeting commit in the history of main. The last command deletes the branch name, not the commit.
Explain it to the duck
When does a merge create a new commit and when does it not?
Tested with: Git 2.51.