In this hands-on lab you will learn how to collaborate on code using pull-requests. The exercise consists of the following parts:
- Setting everything up
- Working with codeowners
- Protecting the main branch
- Working locally
- Creating a pull request
If you have enabled pages in the previous exercise you just have to change the folder from
/(root)
to/docs
.
- Enable GitHub Pages in Settings | Pages for the
/docs
folder and themain
branch. Open the pages URL and verify that the tetris game is visible but too slow.
- Read the issue 🐞 Fix game and see the instructions how to fix the game.
Invite your co-worker and give them write permissions to your repo
Solution
- Go to Collaborators and click
Add people
. Search for your partner and add them to your repo.
- Your partner will receive a notification - but you can also copy the link for the invitation and send it directly.
- Your partner has to accept the invitation.
- Check your local git config with
git config --global user.name
andgit config --global user.email
. - If you don't want to expose your email on GitHub get the email from Email settings and configure name and email accordingly:
git config --global user.name "<your name>"
git config --global user.email "<github-user-id>+<github-user-name>@users.noreply.github.com"
- On windows you should also configure autocrlf:
git config --global core.autocrlf true
. This is normally done when you execute the git setup.
Memory Tip: autocrlf stands for auto carriage return line feed.
Make yourself the global CODEOWNER
for all files - and your partner for all files in the folder docs/
.
Solution
- Create a New file
CODEOWNERS
. - Add yourself as the global owner. Add this ti line 1:
* @<your-github-username>
- Make your partner the owner of the file in the
docs/
folder. Add this to line 2:
docs/ @<your-partners-user-name>
- Commit the file directly to
main
.
Protect the main
branch and enforce reviews from code owners.
Solution
- Create a new Branch Protection Rule
- Set the Branch name pattern to
main
.
- Check Include administrators
- Click create
- Copy the URL to the repository from Code to the clipboard:
- Clone the repository and change into the new folder:
Solution
git clone <paste URL>
cd GitHubBootcamp
Create new local branch users/<user-name>/<issue-id>_fix-game
and switch to it.
Solution
Create the branch and switch to it:
git branch users/<user-name>/1_fix-game
git switch users/<user-name>/1_fix-game
Or switch to a new branch:
git switch -c users/<user-name>/<issue-id>_fix-game
- Modify line 78 in docs/index.html and modify the values like indicated in 🐞 Fix game.
- Add your file to the index:
git add docs/index.html
- Commit your changes:
git commit
- In your editor, enter a title for the commit in line 1. Title should be smaller then 50 characters and written in imperative. What will happen, when this commit is applied. For example:
Fix timing in docs/index.html
- After a blank line add the body. Make sure to break your lines at 70 characters. Add a reference to the issue with a keyord that laters closes the issue (for example closes, fixes, resolves):
This commit fixes the timing error in docs/index.html by setting
correct start and min properties for the speed object.
This commit fixes #1
Safe the file and close the editor. 6. Push your changes:
git push --set-upstream origin users/<user-name>/1_fix-game
Before creating the pull request, ensure that in Settings all options for pull requests are enabled:
Now create a pull request in draft mode. If you have the GitHub CLI installed, you can do it directly from the command line:
gh pr create --fill --draft
Otherwise go to the pull request tab and click Conpare and pull request
:
Note that the title and body of the commit are automatically added to the PR and that the codeowner was added as a reviewer:
Create the PR. The issue will be automatically linked. The PR is still in draft
mode and your partner is not notified, yet. Mark it as ready to enter the the phase and collaborate using reviews:
In this hands-on lab you've learned how to protect your branch, use codeowners, work locally, and create a pull request. Please continue with Review code