Git

Git #

Git is a so-called distributed version control system, originally co-authored by Linus Torvalds to facilitate the development of the Linux kernel.

It was first released in 2005, and has become ubiquitous in software development. For instance, 93.87% of respondents to the 2022 Stack overflow survey declared using it.

Git allows synchronizing the content of a directory (called a repository) across several machines. Notably:

  • each machine contains a copy of the repository and its full history,
  • git allows parallel histories to coexist (in so-called branches), and provides ways to reconcile them.

Warning. Git is not suited to large datasets (more than 1 GB).

Scope of this chapter #

Git has almost 150 commands, each of which may be called with multiple options. But in practice, most users use a handful of these commands on a regular basis.

This chapter only provides a basic introduction and a minimal set of commands, which you are likely to need during the development of you project. Additional resources can be found here.

Terminology #

A difficulty when discovering with git may be it terminology. Here is a very approximative map from git concepts to terms that you are familiar with:

Glossary.

  • a repository: a directory (more exactly, the root directory of a project)
  • a remote server: a non-local server (typically on the cloud)
  • to clone: to copy (a repository)
  • to commit: to save
  • to push: to upload (to a remote server)
  • to fetch: to download (from a remote server)
  • a branch: an alternative history (in your favorite time-travel novel/series/movie)
  • to merge: to reconcile two branches

CLI or GUI #

Many Graphical User Interfaces (GUI) are available for git, and many programs (e.g. probably your IDE) provide some form of git integration.

However, git is mostly used (and almost exclusively taught) via its Command Line Interface (CLI). In addition, the documentation and help that you may find online overwhelmingly relies on its CLI.

Possible explanations are efficiency (autocompletion, aliases, scripts, etc.), transparency, reproducibility, stability over time, etc.

If you use git via CLI, then we recommend using a modern shell for command autocompletion.

If you want a flavor of how a terminal can be configured (for git and other purposes), then you can follow the demo in the dedicated section.

Hosting service #

To collaborate via git and/or back up your repositories, you need to use a git hosting service.

Popular options are GitHub, Gitlab or Bitbucket.

The Unibz also offers a self-hosted Gitlab service.