Skip to content

Creating a Repository

In the Web Interface

After logging in to GitHub, click the + button in top right corner and select New repository (or go to github.kcl.ac.uk/new). Then enter the following details:

  • Owner: your own account
  • Repository Name: we will use git-training
  • Set the visibility to Public (just for this training, to help in case of troubleshooting)
  • We will not add a README file, but use the one we already have instead
  • From the .gitignore template dropdown menu, choose “Python”. (We can talk about what that means at the end of the course.)
  • We won’t select a license right now (though if you ever want to share code with colleagues, please add one for clarity)

… and select “Create repository”.

The newly created repository should look similar to the following screenshot.

A screenshot of a newly created repository on GitHub.

Click on the green “Code” button, then select the “SSH” tab and copy the URL of the repository:

A screenshot demonstrating how to copy the SSH URL of the repository on GitHub.

On CREATE

We have just logged in to CREATE and should now be in your user’s scratch directory /scratch/users/k1234567. (Use pwd to check, if you aren’t certain!)

We can then use git clone to create a copy of the repository on CREATE:

git clone git@github.kcl.ac.uk:k1234567/git-training.git

This will create a new directory, which—by default—has the same name as the repository.

ls  # to see we have a new directory
cd git-training

When we use ls again to list the contents, this directory will look empty, since file names beginning with a dot (so-called “dot-files”) are usually hidden. We can tell the command to show us all files:

ls -a
In addition to the .gitignore file, we see a .git subdirectory. Git uses this special subdirectory to store all the information about the project, including the tracked files and sub-directories located within the project's directory. If we ever delete the .git subdirectory, we will lose the project's history.

We can now start using one of the most important git commands, which is particularly helpful to beginners. git status tells us the status of our project, and better, a list of changes in the project and options on what to do with those changes. We can use it as often as we want, whenever we want to understand what is going on.

$ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

(If you are using a different version of git, the exact wording of the output might be slightly different.)

A few terms here probably require a short explanation:

First, what’s a branch? Git is often used for collaborating with other people and sometimes multiple people may need to edit the same file at the same time. To reduce the risk of conflicts, usually people create a separate “branch” and add any commits on there, without changing the main branch. Later, when they have finished their work, they will “merge” their branch back into the main branch (i.e., add all their commits to the main branch at once). If there are any conflicts with other people’s changes, they can deal with it all at once, during the merge. In this course, we will not be collaborating with others, so it’s fine to do all our work on the main branch. At the end of the day, we’ll share links to training material for more advanced usage.

origin is a local name used to refer to the remote repository we have created on GitHub. It could be called anything, but origin is a convention that is often used by default in git and on GitHub, so it’s helpful to stick with this unless there’s a reason not to.

Info

If you need to create a repository locally without an accompanying copy on a remote server like GitHub, you can use the git init command to do so; see https://swcarpentry.github.io/git-novice/03-create.html for details. For example, this might be necessary if you work in a Trusted Research Environment (TRE) or have other legal restrictions. However, for general usage, creating a repo on the server first and then cloning it makes the setup easier and we would recommend this.