How to Resolve Git Merge Conflicts in VS Code
Use VS Code's conflict editor to understand both sides of a merge conflict and resolve it cleanly without breaking your code.
A merge conflict happens when two changes touch the same lines and git cannot decide which to keep. It looks scary the first time, but VS Code shows both versions clearly and lets you choose. This guide walks through spotting a conflict, reading it, and resolving it with the built-in tools.
What you need
- A git repository open in VS Code
- A merge or pull that produced a conflict (the steps below explain what that looks like)
- A basic understanding of staging and committing
Step 1: Recognize the conflict
When you pull or merge and git cannot reconcile changes, it stops and reports a conflict. In the Source Control view the affected files appear under Merge Changes with a warning icon, and the files contain conflict markers.
Step 2: Read the conflict markers
Open the conflicted file. Git inserts markers around the clashing region. The block after the line with seven less-than signs is your current version (HEAD), and the block after the seven equals signs is the incoming version, ending at the seven greater-than signs. VS Code highlights both and adds clickable actions above them.
Step 3: Choose a resolution
Click one of the action links above the conflict: Accept Current Change keeps your version, Accept Incoming Change takes theirs, and Accept Both keeps both blocks. If neither side is fully right, just edit the text by hand and delete all the marker lines yourself. The goal is code with no markers left.
Step 4: Stage and commit the resolution
Once the file has no conflict markers, save it. In Source Control, stage the resolved file with the plus icon; this tells git the conflict is handled. When every conflicted file is staged, type a commit message and commit to complete the merge.
Result
The conflict is resolved, the markers are gone, and the merge commit is recorded. Your branch now combines both sets of changes the way you intended.
Watch related tutorials
12:47
18:33
15:21
15:22
1:02:14
18:05