🌿 BranchingCommonly used

How to resolve merge conflicts in Git

Fix conflicting changes when merging or rebasing.

1. See which files have conflicts
git status

Files with conflicts are listed under "both modified". Look for conflict markers (<<<<<<<) in those files.

2. Open conflicted files and fix them
# In the file, you'll see:
<<<<<<< HEAD
your changes
=======
their changes
>>>>>>> feature-branch

Remove the conflict markers and keep the correct code (yours, theirs, or a combination).

Most editors (VS Code, IntelliJ) have merge conflict UI — look for "Accept Current", "Accept Incoming" buttons.

3. Stage the resolved files
git add filename.txt

After fixing conflicts in a file, stage it to mark it as resolved.

4. Complete the merge
git commit

Creates the merge commit. Git pre-fills the message with merge details.

Accept all of "ours" for a file
git checkout --ours filename.txt

Keeps your version of the file and discards incoming changes.

When to use: When you know your version is definitively correct for a specific file.

Accept all of "theirs" for a file
git checkout --theirs filename.txt

Keeps the incoming version and discards your changes.

When to use: When the incoming version is definitively correct for a specific file.

← Back to Git Reference