Session 7: Collaboration on GitHub / GitLab

Track, organize and share your work: An introduction to Git for research

Course at General Psychology Lab at the University of Hamburg

Slides | Source

License: CC BY 4.0 DOI

14:15

1 Last session: Integration with GitHub / GitLab

Last session: Learning objectives

After the last session, you should now be able to answer the following questions / do the following:

đź’ˇ You can create a remote repository.
đź’ˇ You can connect your local Git to a remote repository service.
đź’ˇ You can pull and push changes to and from a remote repository.
đź’ˇ You can clone a repository from a remote repository service.

Last session: recipes project

At the end of this session, you should have accomplished the following:

  1. You connected your GitHub account to your local Git.
  2. You created a new GitHub repository and uploaded (i.e., “pushed”) your recipes project.
  3. You collaborated on a shared project by adding and committing changes to a partner’s repository.

Optional:

  1. You cleaned up your project by deleting unnecessary files and branches.
  2. You created a short README.md file in your repository.

Please keep the recipes folder! We will continue to use it in the following sessions.

2 This session: Collaboration on GitHub / GitLab

This session: Collaboration on GitHub / GitLab

Image from Techdobz

This session: Forking & Issues

Link to Pull Request

This session: Forking & Issues

Link to Issue

Reading

https://lennartwittkuhn.com/version-control-book/chapters/github-advanced.html

Learning objectives

Remotes - Advanced

đź’ˇ You can fork a repository.
đź’ˇ You know the purpose and components of a Pull Request.
đź’ˇ You can create a Pull Request from a forked repository.
đź’ˇ You know how to collaborate using the popular workflow strategy GitHub flow.
đź’ˇ You know the purpose and components of a README file.
đź’ˇ You can protect your main branch.

Issues

đź’ˇ You understand the purpose of GitHub Issues.
đź’ˇ You can create and manage Issues.
đź’ˇ You can reference an Issue in another issue.
đź’ˇ You can close an Issue with a commit or pull request.

Cheatsheet

Command Description
git remote Manages remote repositories
git clone Creates a local copy of a repository
git pull Fetches and merges the latest changes from a remote repository into the current branch
git fetch Updates remote tracking branches
git push Uploads local commits to a remote repository

GitHub Flow

Image from Sebass van Boxel

Tasks

In this session, you will work on the following tasks:

  1. Reading: Read the chapter “GitHub - Advanced” in the Version Control Book.
  2. Implementation: Try out the commands in the chapter.
  3. Exercises: Work on the exercises for the recipes project.
  4. Quiz: Test your knowledge with the quiz.

As always:

  1. Try out the commands of this session and play around with them.
  2. Check whether you have achieved the learning objectives.
  3. Ask questions!
  4. Let’s git started!

recipes project

At the end of this session, you should have accomplished the following:

  1. You forked a public / internal recipes repository of another course participant.
  2. You opened an Issue in another repository.
  3. You created a pull request with changes that “fix” the Issue you opened.
  4. You reviewed and merged a pull request to integrate new content from a partner.

Please keep the recipes folder! We will continue to use it in the following sessions.

Exercises

“Public” collaboration with pull requests (using a fork and GitHub Flow)

  1. Find out what forking is.
  2. Fork the recipes repository of another course participant (ideally someone who is not your collaborator from the previous exercise).
  3. Create an Issue in your new collaborator’s repository (maybe their repository is missing a great recipe?).
  4. Repeat the steps from the exercise on collaboration with remote repositories using the forked repository:
    1. Clone the forked repository into a sensible location on your computer.
    2. Create a new branch and create one or multiple commits “fixing” the Issue that you opened. If available, follow the contributing guide of your collaborator’s repository.
    3. Push your changes to the remote repository.
    4. Create a pull / merge request with your changes (hint: from the forked to the original repository) and refer to the Issue in your pull / merge request.

Reviewing pull requests

  1. View any pull requests that are created in your recipes repository.
  2. Review the changes made by the contributor in the pull request.
  3. If needed, discuss additional changes with the contributor in the pull request.
  4. Close the pull request by merging the proposed changes.

🚀 Bonus exercises

  1. Repeat the entire forking workflow with Lennart’s recipes repository. Find out about the contributing guidelines in Lennart’s repo and follow them when creating a new recipe.

Solutions

  1. Forking is a process where you create a copy of someone else’s repository under your own account. It allows you to freely experiment with changes without affecting the original project.
  2. To fork the recipes repository of another course participant: (1) Go to the GitHub repository you want to fork. (2) Click the Fork button at the top-right corner of the repository page. (3) Select your GitHub account to fork the repository.
  3. Create an Issue, suggesting a missing recipe: (1) Go to the Issues tab of your partner’s repository on GitHub. (2) Click New issue. Provide a title and description for the Issue, suggesting a missing recipe. (3) Click Submit new issue.
  4. Clone the forked repository into a sensible location on your computer.
Code
git clone https://github.com/your-username/forked-repo-name.git /path/to/your/forked/directory
cd /path/to/your/forked/directory
  1. Create a new branch and create one or multiple commits “fixing” the Issue that you opened.
Code
git checkout -b issue-fix-branch
echo "New Recipe Content" >> recipes.txt
git add recipes.txt
git commit -m "Add new recipe to fix #1"
  1. Push your changes to the remote repository:
Code
git push origin issue-fix-branch
  1. Create a pull request with your changes (from the forked to the original repo) and refer to the issue in your pull request:

    1. Go to your forked repository in your browser.
    2. Click the Compare & pull request button.
    3. Ensure that the base repository is the original and the base branch is main.
    4. Provide a title and description for your pull request.
    5. Refer to the issue by adding Fixes #issue-number in the description.
    6. Click Create pull request.
    7. Review any pull requests in your repository.