Skip to content
Justice Tech School

Merge Commits

If both branches moved, Git makes a merge commit with two parents.

Example
echo one > a.txt && git add a.txt && git commit -qm 'first'
git switch -q -c feat
echo f > f.txt && git add f.txt && git commit -qm 'feat'
git switch -q main
echo m > m.txt && git add m.txt && git commit -qm 'main work'
git merge --no-edit feat >/dev/null
git log --format='%s (%p)' -n 1 | sed 's/(.*)//'
git log --merges --oneline | wc -l

Result

Merge branch 'feat' 
1

Exercise

Always merge commit.

git merge  feat

Quiz Test

How many parents has a merge commit?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.