Skip to main content

Forking a Git Repository

A common way to run classes at the CCI is for your lecturer to manage homework through a main git repository that they update with new files weekly, and ask you to make a fork of it to complete the work. Once you have a fork of the repository set up properly, this can be a very efficient workflow, but it takes a bit of getting used to!

In order to follow these instructions, make sure that you have first gone through the process of creating a CCI Github account and setting it up locally.

Step 1: make a fork of the remote repository

This step should be completed in your browser. Navigate to the repository you want to fork, e.g. the one that your lecturer made, and click the 'fork' button. This will take you to a page that allows you to name your copy -- you can either change this, or leave it the same, it won't affect the function. If you have already made a fork, it will link you to your existing copy.

Once you have created the fork, it will take you to your copy of the repository. This should look the same as the original, but this one belongs to you! Note that the name of the person who owns the repository has changed, but it contains a link to the original repository underneath the main title.

Step 2: clone your fork locally

Next, you want to create a local copy of your fork. It's important that you clone your repo, not the original one! That's because your one is the one you have permission to update and publish.

To make a local copy, navigate to the 'Code' tab and copy the 'SSH' version of the URL, not the HTTPS!

Open your terminal, and navigate to the folder you want to create your repo in. Make sure you don't clone the repository inside an existing git repo -- this will cause you problems. In this instance, I'm going to clone my repository to Desktop:

so, the commands are:

cd path/to/repo
git clone git@git.arts.ac.uk:yourname/repo-name.git
cd repo-name

Step 3: add the original repository as an upstream branch

Now, you have a local copy of your code. You can add, commit and push to your fork of the repository, and this will work just like a repository that you made. However, if your lecturer is regularly publishing changes to your code, you will also want to link their repository as what's called the upstream branch, so you can regularly pull and incorporate their changes.

In order to do this, we want to look at the state of the remotes. The remote branches point to copies of the repository that exist online. You want the origin branch to be to a repository that you own, and to have the upstream point to your lecturer's repository.

To inspect your remote