Git Merge and Merge Conflict (original) (raw)

Last Updated : 7 May, 2026

Git merge combines changes from different branches into one for smooth integration. If Git can’t merge changes automatically, a merge conflict occurs and must be resolved manually.

Example Scenario

You are working on a dev branch where you create a file k.txt and commit it. When you check the logs, you’ll see a commit showing that k.txt was added in the dev branch.

This can be broken into steps:

1. Merging Changes

In the above example, merging is used to bring k.txt from the dev branch into the master branch.

git checkout master
git merge dev

merging-changes

Output

Now k.txt appears in the master branch.

Note: master and main are default branch names in Git. Older versions use master while newer versions use main, but both serve the same purpose as the primary branch.

2. Merge with a Commit

In the same scenario, if Git performs a fast-forward merge, it will only move the branch pointer without creating a new commit.

But if you want a separate commit to clearly show that dev was merged, you can use --no-ff.

git merge dev --no-ff -m "Merged dev into master"

merge_with_commit

Output

Now a new merge commit is added to the history.

3. Merge Conflict

Now imagine another situation in the same example:

When you try to merge, Git cannot decide which version to keep which creates a conflict.

merge_conflict

Output

**Example Conflict:

k_txt

Output

**Resolution: Edit k.txt with the desired content, then run:

git add k.txt
git commit -m "Resolved Conflict"

Screenshot-2026-03-18-124647

Output

After resolving, the merge completes successfully.

4. Aborting a Merge

If during this process you feel the merge is incorrect or too complex, you can cancel it.

git merge --abort

abort

Output

This brings your project back to the state before the merge started.