In this lab, you're going to resolve merge conflicts in the GitHub UI as well as the command line.
Several teammates have made adjustments to the game to change the difficulty. It's up to you to review their pull requests, resolve any conflicts, and merge their changes!
In this task, you will merge the first feature change in the GitHub UI. After this, you will see that there is a merge conflict in the second pull request. You will resolve this conflict in the next task.
-
In your browser, navigate to your repository on GitHub
-
Click on the Pull requests tab
-
Click one of the pull requests titled
Increase the number of starting tiles
-
Click the Files changed tab
Note that this PR changes the number of starting tiles in the game.
-
Click Review changes
-
Select Approve
-
Click Submit review
You will be redirected back to the Conversation tab of the PR.
-
Click Merge pull request
-
Click Confirm merge
Now that the first PR has been merged, you'll see that the second PR has a merge conflict. In this task, you will resolve this conflict using the GitHub UI.
-
Click on the Pull requests tab
-
Click on the remaining pull requests titled
Increase the number of starting tiles
Note that the PR has a merge conflict in
src/game_manager.ts
. -
Click Resolve conflicts
You will be directed to the conflict resolution page. There, you will see the changes introduced by the PR, as well as the current changes in the
main
branch (the ones you merged in the previous task)./** Start Tiles Count */ <<<<<<< feature/start-tiles-3 static startTiles: number = 4 ======= static startTiles: number = 2 >>>>>>> main
The
<<<<<<<
,=======
, and>>>>>>>
lines are conflict markers. The<<<<<<<
line indicates the beginning of the conflicting changes, the=======
line separates the conflicting changes, and the>>>>>>>
line indicates the end of the conflicting changes.To resolve the conflict, you need to choose which changes to keep and which changes to discard. In this case, you want to keep the changes from the PR and discard the changes from
main
. -
Delete the
<<<<<<<
,=======
, and>>>>>>>
lines -
Delete the changes from
main
(thestatic startTiles: number = 2
line)The updated lines should look like this:
/** Start Tiles Count */ static startTiles: number = 4
-
Click Mark as resolved
-
Click Commit merge
You will be redirected to the Conversation tab of the PR. At this point, there should no longer be a merge conflict.
-
Click the Files changed tab
-
Click Review changes
-
Select Approve
-
Click Submit review
You will be redirected back to the Conversation tab of the PR.
-
Click Merge pull request
-
Click Confirm merge
In this task, you will merge the first pull request in the GitHub UI. After this, you will see that there is a merge conflict in the second pull request. You will resolve this conflict in the next task.
-
In your browser, navigate to your repository on GitHub
-
Click on the Pull requests tab
-
Click one of the pull requests titled
Increase rate of tiles with value 4
-
Click the Files changed tab
Note that this PR changes the rate that determines the value of new tiles.
-
Click Review changes
-
Select Approve
-
Click Submit review
You will be redirected back to the Conversation tab of the PR.
-
Click Merge pull request
-
Click Confirm merge
Now that the first PR has been merged, you'll see that the second PR has a merge conflict. In this task, you will resolve this conflict using the GitHub UI.
-
Click on the Pull requests tab
-
Click on the remaining pull requests titled
Increase rate of tiles with value 4
Note that the PR has a merge conflict in
src/game_manager.ts
. -
Open your local clone of the repository
-
Pull the updates to the
main
branchgit checkout main git pull
-
Switch to the branch for the PR
git checkout feature/tile-value-1
-
Merge the
main
branch into the PR branchgit merge main
You will see a message similar to the following:
Auto-merging src/game_manager.ts CONFLICT (content): Merge conflict in src/game_manager.ts Automatic merge failed; fix conflicts and then commit the result.
-
Open
src/game_manager.ts
in your text editorYou will see that the file has been updated to include conflict markers.
static addRandomTile(): void { if (Grid.cellsAvailable()) { <<<<<<< HEAD const value = Math.random() < 0.1 ? 2 : 4 ======= const value = Math.random() < 0.5 ? 2 : 4 >>>>>>> main const cell = Grid.randomAvailableCell() if (cell !== null) Grid.insertTile(new Tile(cell, value)) } }
The
<<<<<<<
,=======
, and>>>>>>>
lines are conflict markers. The<<<<<<<
line indicates the beginning of the conflicting changes, the=======
line separates the conflicting changes, and the>>>>>>>
line indicates the end of the conflicting changes.To resolve the conflict, you need to choose which changes to keep and which changes to discard. In this case, you want to keep the changes from the PR and discard the changes from
main
. -
Delete the
<<<<<<<
,=======
, and>>>>>>>
lines -
Delete the changes from
main
(theconst value = Math.random() < 0.5 ? 2 : 4
line)The updated lines should look like this:
static addRandomTile(): void { if (Grid.cellsAvailable()) { const value = Math.random() < 0.5 ? 2 : 4 const cell = Grid.randomAvailableCell() if (cell !== null) Grid.insertTile(new Tile(cell, value)) } }
-
Add the change to the staging area
git add src/game_manager.ts
-
Commit the change
git commit -m 'Merge main into feature/tile-value-1'
-
Push the change
git push
The PR will be updated with the new commit that resolves the merge conflict.
-
Navigate to the PR in your browser
-
Refresh the page
You should see that the PR no longer has a merge conflict.
-
Click the Files changed tab
Note that this PR changes the rate that determines the value of new tiles.
-
Click Review changes
-
Select Approve
-
Click Submit review
You will be redirected back to the Conversation tab of the PR.
-
Click Merge pull request
-
Click Confirm merge
If you're having trouble with any of the steps, you can ask for help in the meeting chat.