Git For Analysis

Last update: 10 Nov 2020 [History] [Edit]

There are many tutorials available for understanding how code in Git and GitLab can be organised, many examples of these can be found in the additional resources section below. If you are new to Git and need to learn the basics, please take the time to read through these.

This tutorial intends to give a general overview of some topics and how you would use Git and GitLab for analysis.

It is not meant to replace the ATLAS git tutorial which explains how to use git, with a particular focus on offline software

Creating a Git Repository

The first thing you’ll want to do is to create a project in git where you will put your analysis code. The project can reside in a user, institute or group repository. To create a project in your personal repository, you can go to<your cern username>

and click on “New project”.

You will then need to give a name to the project (“MyAnalysis” for example) and set a visibility level. For the latter, it is best if you keep this at the default value: “Private”. This ensures that non-ATLAS users with CERN gitlab access are unable to access your repository.

Creating a local repository

Let’s make a repository on lxplus as a copy of the xAOD analysis skeleton and use that for the tutorial.

mkdir SoftwareEssentials
cd SoftwareEssentials
mkdir build 
mkdir run 

Copy your source directory from the xAOD tutorial or copy an analysis skeleton from /afs/ and cd in there and use it as your directory for Git.

Initialise your repository

You need to initialise the Git repository so you can start committing your code in git.

git init
# You should see this message
Initialized empty Git repository in ...

Where ... is your working directory here

If you do git status now you will see all your files are not tracked and you need to stage, commit and push them to our remote project we set up earlier. Maybe add a README if you feel like it.

First we need to link our local repository with the remote GitLab repository and then we are free to stage, commit and push.

git remote add origin<username>/<projectname>.git
git add .
git commit -m "First Commit"
git push -u origin master

Replace username and projectname with the relevant inputs for you and your project.

Take extra care with the final line, origin is the default name for the remote and master is the name of the branch. Consult the basic material for more information on this.

Git Configuration

Setting your name and email Configure git to add your name and email to every commit, using git config. We’d recommend you use your CERN account email and name so that the names on local commits match the ones you’ll create via gitlab.

To change this you can run

git config --global <your cern name>
git config --global <your cern email>

Colour You can also change the colour of your messages from git, tracked files will be shown in red and staged files shown in green etc etc.

git config --global color.ui auto