git merge

Bring the changes from another branch into the current one

What it does

git merge brings the commits of the branch you name into the current branch. Usually you first switch to the branch you merge into (say, main) and run git merge there with the name of the task branch.

If the current branch has not moved since, git simply moves it forward (fast-forward). If both have changed, git creates a merge commit. When the same lines were changed differently in both branches, you get a conflict: git marks those places in the files, you fix them by hand, stage them with git add and finish the merge with git commit. git merge --abort cancels the merge and puts everything back.

Syntax

git merge <branch>
git merge --abort

Examples

Related commands

Practise · All commands