This tutorial walks you through simulating a merge conflict and resolving it manually.
These steps are to be done by One Person in your group. The other person will have things to do in the future don't worry! Please be sure to pay attention though.
- You can fork this repository by clicking the fork icon at the top. This will copy the repository into your Github account.
- Expand the code button, select HTTPS, and copy the url.
- Open your terminal (or Git Bash), then run:
git clone <url>
cd Github-Workshop-Demo2- Create a text file called adventure.txt using the
touchcommand - Add and commit your file
git add .
git commit -m "Add adventure.txt"
git pushPerson 1, add person 2 as a collaborator on your new github repo!
Follow the steps in section 1.2 to clone the same repository to your local working environment.
Create your own branches with different names and switch to it. The -b flag is a shortcut from doing git branch [branch_name] first.
git checkout -b [branch_name]On your local adventure.txt files, write these edits to them
- Person 1:
The hero finds a magical sword.
- Person 2:
The Hero swings and misses.
Save, then:
git add story.txt
git commit -m "updates!"push your new changes
git pushPerson 1 ones a pull request, adds a short description, and adds Person 2 as a reviewer.
Person 2 goes to Changed Files, reviews the changes and merge the pull request. You should have no conflicts at this point.
Person 2 goes back to the main branch and pull the new changes
git checkout main
git pullPerson 2 tries to merge their branch into main.
git merge [branch_name]You should see, and on VSCode, adventures.txt will open with the conflicts
Auto-merging adventure.txt
CONFLICT (content): Merge conflict in story.txt
Automatic merge failed; fix conflicts and then commit the result.Manually edit it to something like
The Hero finds a magical sword.
The Hero swings and missesthen mark it resolved and commit confirm merge on VScode.
git add adventure.txt
git commit -m "Resolve merge conflict"push your updated main branch
git pushIf you’re done with the exercise, you can delete your branches:
git branch -d [branch_name]
git push origin --delete [branch_name]