Git 2 reference · Branching and Merging

git merge Command (Git)

Combine another branch into the current one, fast-forwarding when possible or creating a merge commit.

Git 2

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git merge [--no-ff] [--abort] BRANCH

Parameters

ParameterDescription
--no-ff Always create a merge commit.
--ff-only Refuse unless it can fast-forward.
--abort Give up a conflicted merge.

Examples

A fast-forward merge
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git switch -q -c feature
echo f > feature.txt; git add .; git commit -q -m 'Add feature'
git switch -q main
git merge -q feature && git log --oneline

Output

c0ec713 Add feature
7f7f133 Initial commit

Run this on your computer — see “Get Started” for setup.

A conflict, then aborting
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git switch -q -c a; echo a > README.md; git commit -q -am 'a version'
git switch -q main; echo main > README.md; git commit -q -am 'main version'
git merge a > /dev/null || git status -s
git merge --abort; git status -s | wc -l

Output

UU README.md
0

Run this on your computer — see “Get Started” for setup.

To resolve a conflict instead, edit the files to remove the <<<<<<<, ======= and >>>>>>> markers, git add them and run git commit.

Was this page helpful?