Merge a Branch
Merge joins two lines of work into one. It takes the snapshots from another branch and adds them to yours.
See the split first
Two lines grew apart. One added apples. The other added a weekend plan.
$ git log --oneline --graph --allJoin the branch
The -m form writes the merge message without opening an editor.
$ git merge shopping-list -m "Merge shopping-list into main"See the join
The merge snapshot sits on top, with two parents below it.
$ git log --oneline --graphExample
$ git merge shopping-list -m "Merge shopping-list into main"
$ git log --oneline --graphKey points
- Merge with a branch name joins that branch into yours.
- Git makes a merge snapshot when the lines split apart.
- The merge snapshot has two parents.
- The graph shows the split and the join.
- Merge from main so the new work lands on the main line.
- Delete the branch after the merge.
Here, the merge joins the apples line into main. The graph shows the split and the join, and the merge snapshot keeps both parents.
Note
A merge never deletes work. Both lines stay in the history.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does git merge do?