Git

Git is a version control system: a tool that records the history of the files in a project. With Git you can go back to any earlier version of your work, see exactly what changed, when and why, try out ideas without fear of breaking what already works, and combine your work with that of your collaborators. It is free and open source, and it is by far the most widely used version control system, for everything from analysis code and papers to large software projects like ROOT or the software of the LHC experiments.

This lesson will teach you to use Git on your own computer to keep track of your work, and then to collaborate with others through a shared repository.

Git, GitLab and GitHub

Git is the program that runs on your computer and keeps the history of your project. GitLab, GitHub and similar services are websites that host copies of Git repositories online, so that you can share them, and they add collaboration tools on top, such as merge requests, issues and continuous integration. CERN runs its own GitLab instance at gitlab.cern.ch.

You can use Git entirely without any of these websites, and the first part of this lesson does exactly that.

XKCD about Git

If this comic feels familiar, don’t worry: by the end of this lesson you will know what those commands actually do.

Before you start

  • Git installed on your computer, version 2.28 or newer. You can check with git --version; if you need to install or update it, see git-scm.com. Git is already available on lxplus.

  • Some familiarity with the shell: moving between directories and running commands. The shell lesson covers everything you need.

  • For the collaboration part of the lesson: an account on CERN GitLab (you can log in with your CERN computing account) or on GitHub, with an SSH key added to it, as explained in Remotes in CERN GitLab.

The lesson is organised in four parts, followed by a reference page:

Part 1: Using Git on your own

Part 2: Collaborating with others

Part 3: Automation

Part 4: Sharing your research

  • Open Science: how version control supports open and reproducible research.

  • Licensing: choosing a licence so that others can reuse your work.

  • Citation: making your work easy to cite.

Reference

  • Git Command Reference: all the commands from this lesson on one page, for quick lookup, and a glossary of Git terms.