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.
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
Automated Version Control: what version control is and why it is worth using.
Setting Up Git: configuring Git the first time you use it.
Creating a Repository: starting to track a project with Git.
Tracking Changes: the modify-add-commit cycle and writing good commit messages.
Exploring History: comparing versions, restoring old files and undoing commits.
Ignoring Things: telling Git which files not to track.
Branching and Merging: working on several things in parallel and combining them.
Part 2: Collaborating with others
Remotes in CERN GitLab: putting your repository online and keeping it in sync.
Sharing a Repository with Others: cloning and working on a shared repository.
Tracking Work with Issues: reporting bugs, planning work and discussing it next to the code.
Collaborating with Pull Requests: proposing changes through forks, branches and merge requests.
Conflicts: what happens when changes overlap, and how to resolve them.
Part 3: Automation
Continuous Integration: running tests and other tasks automatically every time you push, with GitLab CI.
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.
