Dark theme

GitHub basics


Git is a system that allows you to keep track of different versions of your code (and data). You can also set up an internet address where others can get hold of the work. A popular implementation of this is the GitHub website (Wikipedia), which provides free space for Open Source projects, including website space. GitHub is popular to the point that Git and GitHub are almost synonymous. This tutorial will walk you through using both together, using GitHub's version of the Git software.


Git is a code repository and versioning/revision control system, that is, it sets up somewhere you can store code and which keeps track of different versions of your code so you can undo/"roll back" changes if you need to. However, as code is just text, it also allows for uploading and tracking of other stuff, such as data.

Git is also a distributed revision control system. Multiple people can work on the same code. There is a central storage place for any given project (often on GitHub), but each user also has their own copy of this repository (or "repo") which encapsulates their changes. A coder starts by pulling the code from the online version (if there is any). They can then make changes on their local machine. When they want to alter the online copies, they can push their copy of the repository back to the online store. If there are changes from multiple people since a coder last pulled the code down, these changes will be merged, and any conflicts manually managed by either the coder or an administrator.

The final thing to understand is that the local repository is only really a record of versions you have decided to tell it to note. You work on an independent copy of the code, and have to commit changes (update your copy of the repository) when you want to store those changes locally. Once changes are committed you can carry on working, knowing you have the option to roll back to that version if you want. Whenever you are happy the code is in a good enough state for everyone else, you commit it locally, and then push the local committed version to the online repo for everyone. The usual sequence is therefore:

pull online repo --> edit --> commit to record locally --> push to online repo.

So, now we've got the basic idea, let's set up a repository, and try some pushing and pulling.


The first thing you'll need to do is to set up a GitHub account. Go to the GitHub site and do that now. Obviously only do this if you are happy with their terms and conditions. Choose a username with all lower case letters and numbers, anything else may cause problems with setting up a website as instructed.

There is a history of GitHub on Wikipedia if you are interested.

Notes:

Other popular sites for storing and managing code are GitLab, Sourceforge, CodePlex, and BitBucket. If you don't like their terms, you could use Git (or Mercurial, or Subversion or similar) and set up your own repository system.

For a brief explanation of what open code is, why you should make your code, and how, see: the UKRN primer on Open Code and Software. For a fuller argument, and example case studies, check out The Cathedral and the Bazaar.


Once you've set up an account, go to look at using Git to keep track of changes locally.