3  Collaborating with Github

Key terms

fork - a copy of a repo on GitHub that is connected to the original pull request - a system for suggesting edits and additions to the owner of the original repo from your fork origin - conventional name for the remote of your fork upstream - conventional name for the remote of the original repo

GitHub is useful for developing your own code, but at some point you might want to collaborate with other people on a project. Or you might come across a GitHub repository that you want to use as a starting point for your own work. In both cases forks are the way to go.

3.1 Different ways to collaborate with github

  • Branches: as you saw in (previous page) collaborators can create branches and suggest changes
  • Forks: Forking creates a copy of a repository

In terms of reviewing and integrating these changes we use a pull request

#7: Forktocat © GitHub, Inc.

3.2 Forking a repository

A fork is a copy of somebody’s GitHub repository. You can fork a repo and work independently of the original project. Or if you are collaborating with other people you can stay connected with the original repository via pull requests.

You cannot directly affect (or damage) the original project.

3.3 Clone a repository

Besides forking a repository, you can also clone a repository from GitHub.com to your local computer. Cloning a repository creats a full copy of all files in the repository at that point in time.

3.3.1 Using Git

First, navigate to the directory where you want to clone the repository:

cd /path/to/your/directory

Next, copy the repository URL from GitHub (e.g., using HTTPS), and run the following:

git clone https://github.com/BecksLab/tutorial_github.git

3.3.2 Using GitHub desktop

To clone the repository with GitHub Desktop, click Open with GitHub Desktop under the Code.

3.3.3 Using VScode

To clone a repository in VScode, select the Clone Repository button in the Source Control view. Then enter the repository URL copied from GitHub or select a repository from the list to clone to your computer.

3.4 Creating pull requests

  • Think of this as a ‘track changes’ version of the repository. It is possible to see how the ‘new’ version differs from the current (main) version and you can see what has been added and what has been removed.
  • Allows you to suggest/request changes before merging into main

3.5 Merging changes

3.6 A collaborative workflow

Insert basic schematic that links all of the concepts of collaborative work - upstream, changes, pull requests, review

3.7 Troubleshooting

References