Git¶
Git basics¶
git is a distributed and fast version control system that records changes to a file or set of files over time so that you can recall specific versions later.
Mainly used by programmers to keep track of their code, theoretically can be used for every files (e.g. writing a novel)
!git help config # to open documentation on a command, e.g. config
First setup steps
# !git config --global user.email youremail@domain.com
# !git config --global user.name "yourname"
Initialize git in a directory¶
git helps keep track of changing data in a directory (called repository) through snapshots
You start traking a directory (i.e. create a repository) by running through the terminal, while inside the directory to track, git init.
!mkdir first_git_repo
!git init first_git_repo
!ls -al first_git_repo
Then, you will find a .git hidden directory that git uses to store all information
Track a file¶
!touch first_git_repo/new_file.txt # sintetic file that we want to track
# The following works only within a terminal inside first_git_repo directory
# Here are shown for example
# !git add first_git_repo/* # Propose a change: add to the tracked index all file inside repo
# !git commit -m "first commit" # create the snapshot (commit) with a comment
Local vs Remote¶
git is a software that operates on local files in your computer
There are remote services that store files online and use git as reference: github, gitlab, codeberg etc.
The porpuse¶
Git can serve multiple purposes, mainly:
- versioning your files: keep their history (and revert changes if needed!)
- branching: working on multiple versions concurrently
- multiple developer can collaborate on a single project
- ...
Git is distributed¶
Every developer has a complete copy of the repository, including its full history. Work can be done and tracked locally, and changes are shared by pushing to and pulling from a remote

Clone (i.e. download) a repository from remote¶
Commands are shown as example
# !git clone https://gitlab.hpc.cineca.it/training/python-intro-feb2026
Local and remote repository are independent, they has to be kept in-sync by the user
# !git push origin main # push changes from main (local) to origin (remote)
# why remote is called origin? it is a common name, check `git remote -v` to check remote names
# why local is called main? it's common
# !git pull # pull changes from origin (remote) to main (local)
To do to update the material:¶
# inside the root of python-intro-feb2026 directory
git add *
git commit -m "personal changes"
git pull
In case of merge conflics, posible solutions:
- specify a merge policy (before a
git pull):git config pull.rebase true - clone again the repo in a new directory (quick and dirty, use it just for this course)
- manully resolve conflics and then
git merge