Skip to content

Latest commit

 

History

History
183 lines (121 loc) · 6.66 KB

03-Collaborate-on-code.md

File metadata and controls

183 lines (121 loc) · 6.66 KB

🔨 Hands-on: Collaborate on code

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

Enable GitHub Pages

If you have enabled pages in the previous exercise you just have to change the folder from /(root) to /docs.

  1. Enable GitHub Pages in Settings | Pages for the /docs folder and the main branch. Open the pages URL and verify that the tetris game is visible but too slow.

Review the issue to fix

  1. 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

Invite your co-worker and give them write permissions to your repo

Solution
  1. Go to Collaborators and click Add people. Search for your partner and add them to your repo.
image
  1. Your partner will receive a notification - but you can also copy the link for the invitation and send it directly.
image
  1. Your partner has to accept the invitation.
image

Check your local git config

  1. Check your local git config with git config --global user.name and git config --global user.email.
  2. 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"
  1. 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.

Working with codeowners

Make yourself the global CODEOWNER for all files - and your partner for all files in the folder docs/.

Solution
  1. Create a New file CODEOWNERS.
  2. Add yourself as the global owner. Add this ti line 1:
* @<your-github-username>
  1. Make your partner the owner of the file in the docs/ folder. Add this to line 2:
docs/ @<your-partners-user-name>
  1. Commit the file directly to main.

Protecting the main branch

Protect the main branch and enforce reviews from code owners.

Solution
  1. Create a new Branch Protection Rule
  2. Set the Branch name pattern to main.
image
  1. Check Include administrators
  2. Click create

Working locally

Clone the repository

  1. Copy the URL to the repository from Code to the clipboard:

image

  1. Clone the repository and change into the new folder:
Solution
git clone <paste URL>
cd GitHubBootcamp

Create a local branch

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

Do changes to the file

  1. Modify line 78 in docs/index.html and modify the values like indicated in 🐞 Fix game.
  2. Add your file to the index:
git add docs/index.html
  1. Commit your changes:
git commit
  1. 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
  1. 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

Creating a pull request

Before creating the pull request, ensure that in Settings all options for pull requests are enabled:

image

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: image

Note that the title and body of the commit are automatically added to the PR and that the codeowner was added as a reviewer:

image

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:

image

Summary

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