Topic 4

Conflict

A conflict is not a disaster. It simply means Git needs help choosing between overlapping edits.

What a conflict means

If GitHub has changes that are not yet on your computer, VS Code may stop the push and ask you to pull first. Pull brings those GitHub changes into your local project and tries to combine them with your work.

If the two versions changed the same part differently and Git cannot combine them automatically, it asks you to choose the final content. This is a conflict.

VS Code warning that a push was rejected and a pull is required

Before pulling, run git status. If it shows uncommitted work, commit that work or temporarily save it with git stash.

After that warning, click ‘Cancel’. Execute the command “pull”.

Then you will be able to see the following screen where the staging will be canceled. The green box displays the modifications made locally, while the blue box displays the content from GitHub.

VS Code source control panel after staging is canceled during a merge conflict

Three options

There are three options, and you can click the one you prefer:

Option What happens
Accept Current Change Only the modifications made locally will be accepted, and the content on GitHub will be discarded.
Accept Incoming Change The modifications made locally will be discarded, and only the content on GitHub will be accepted.
Accept Both Changes Both versions will be kept. To avoid accidentally discarding either version, the safest workflow is to choose this option first and then have the author review and edit the combined result, removing duplicated or incompatible text.
VS Code conflict options for accepting current, incoming, or both changes

For example, if you click on ‘Accept Both Changes’, you will see a screen similar to the one on the right. Before compiling or saving, the author should review the combined code and text, remove duplicated content, and reconcile any incompatible lines. Compile or save only after confirming the intended final result.

VS Code conflict editor with Accept Both Changes highlighted
VS Code editor after both conflict changes are accepted

Before staging the resolved file, run:

git status
git diff

Confirm that no conflict markers remain, review the exact combined changes, and compile or build the document. Stage and commit only after these checks pass.

Finish the merge

In the source control, click on the ‘+’ button in ‘Merge Changes’, and also click on the ‘+’ button in ‘Changes’. Then you will be able to see that all the changes have been staged, just like the screen on the right.

VS Code Source Control with Merge Changes ready to stage
VS Code Source Control with Changes ready to stage
VS Code Source Control after all conflict changes are staged

Proceed with the command “Commit & Push”. Thus, the conflict has been resolved.

VS Code Source Control menu with Commit & Push highlighted

If you can explain what the final file should say and the repository returns to a clean state afterward, the conflict has been handled correctly.