In this lab, you're going to use git cherry-pick to move commits between
branches.
Let's "accidentally" commit some changes to main, then cherry-pick them into a
feature branch and remove the commits from the default branch.
-
Ensure you are on the
mainbranchgit checkout main
-
Create a new branch called
feature/new-gamegit branch feature/new-game
Note
The difference between git branch and git checkout -b is that the former
only creates the branch, while the latter creates the branch and checks it
out.
-
Locate the comment
// Lab 5: New Game Button -
Add the following code below the comment
// Lab 5: New Game Button KeyboardInputManager.bindButtonPress( '.restart-button', KeyboardInputManager.restart )
-
Save the file
-
Add the changes to the staging area
git add src/keyboard_input_manager.ts
-
Commit the changes
git commit -m "Add new game button listener"
At this point, the main branch has a new commit that is meant for the
feature/new-game branch!
-
Get the commit SHA of the most recent commit on the
mainbranchgit log --oneline -n 1
Copy the SHA of the commit.
-
Switch to the
feature/new-gamebranchgit checkout feature/new-game
-
Cherry-pick the commit from the
mainbranchReplace
COMMIT_SHAwith the SHA of the commit you copied in the first step.git cherry-pick COMMIT_SHA
-
Switch back to the
mainbranchgit checkout main
-
Reset
mainto the commit before the new game button listenergit reset --hard HEAD~1
-
Verify that latest commit on
mainis no longer the new game button listener updategit log --oneline -n 1
-
Merge the
feature/new-gamebranch into themainbranchgit merge feature/new-game
-
Push your changes to GitHub
git push
-
Navigate to your repository on GitHub.com
-
Click the Actions tab
-
Click the running Deploy to GitHub Pages workflow
-
Wait for the workflow run to complete
-
Click the Code tab
-
Click the link to your game
-
Verify the New Game button now restarts the game
If you're having trouble with any of the steps, you can ask for help in the meeting chat.
The code changes for this lab can be found in the solutions directory.
- Copy the contents of
solutions/5-cherry-pick/keyboard_input_manager.tsand replace the contents ofsrc/keyboard_input_manager.ts