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.
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.
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. |
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.
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.
Proceed with the command “Commit & Push”. Thus, the conflict has been resolved.
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.