Software Engineering for Self-Directed Learners »

Tools → Git and GitHub →

Preparing to Use Git


Before you start learning Git, you need to install some tools in your computer.

This lesson covers that part.

Installing Git

Git is a free and open source software used for revision control. To use Git, you need to install Git on your computer.

PREPARATION: Install Git

Download the Git installer from the official Git website.
Run the installer and make sure to select the option to install Git Bash when prompted.

When running Git commands, we recommend Windows users to use the Git Bash terminal that comes with Git. To open Git Bash terminal, hit the key and type git bash.

SIDEBAR: Git Bash Terminal

Git Bash is a terminal application that lets you use Git from the command line on Windows. Since Git was originally developed for Unix-like systems (like Linux and macOS), Windows does not come with a native shell that supports all the commands and utilities commonly used with Git.

Git Bash provides a Unix-like command-line environment on Windows. It includes:

  • A Bash shell (Bash stands for Bourne Again SHell), which is a widely used command-line interpreter on Linux and macOS.
  • Common Unix tools and commands (like ls, cat, ssh, etc.) that are useful when working with Git and scripting.

Install homebrew if you don't already have it, and then, run brew install git


Use your Linux distribution's package manager to install Git. Examples:

  • Debian/Ubuntu, run sudo apt-get update and then sudo apt-get install git.

  • Fedora: run sudo dnf update and then sudo dnf install git.


Verify Git is installed, by running the following command in a terminal.

git --version
git version 2._._

The output should spit out the version number.


Configuring user.name and user.email

Git needs to know who you are to record changes properly. When you save a snapshot of your work in Git, it records your name and email as the author of that change. This ensures everyone working on the project can see who made which changes. Accordingly, you should set the config settings user.name and user.email as before you start Git for revision control.

PREPARATION: Set user.name and user.email

To set the two config settings, run the following commands in your terminal window:

git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"

To check if they are set as intended, you can use the following two commands:

git config --global user.name
git config --global user.email

Interacting with Git: CLI vs GUI

Git is fundamentally a command-line tool. You primarily interact with it through its by typing commands. This gives you full control over its features and helps you understand what’s really happening under the hood.

clients for Git also exist, such as Sourcetree, GitKraken, and the built-in Git support in editors like Intellij IDEA and VS Code. These tools provide a more visual way to perform some Git operations.

If you're new to Git, it's best to learn the CLI first. The CLI is universal, always available (even on servers), and helps you build a solid understanding of Git’s concepts. You can use GUI clients as a supplement — for example, to visualise complex history structures.

Mastering the CLI gives you confidence and flexibility, while GUI tools can serve as helpful companions.

PREPARATION: [Optional] Install a GUI client

Optionally, you can install a Git GUI client. e.g., Sourcetree (installation instructions).

Our Git lessons shows how to perform Git operations in Git CLI, and in Sourcetree -- the latter just to illustrate how Git GUIs work. It is perfectly fine for you to learn the CLI only.


[image credit: https://www.sourcetreeapp.com]


Installing the Git-Mastery App

In these lessons, we are piloting a new companion app called Git-Mastery that we have been developing to help Git learners. Specifically, it provides exercises that you can do to self-test your Git knowledge, and the app will also verify if your solution is correct.

If you are new to Git, we strongly recommend that you install and use the Git-Mastery app.

PREPARATION: [Recommended] Install and Configure the Git-Mastery App

1. Install the Git-Mastery App


brew tap git-mastery/gitmastery
brew install gitmastery

Ensure you are running libc version 2.38 or newer.

Then install the app by running the following commands:

sudo apt install software-properties-common
sudo add-apt-repository "deb https://git-mastery.github.io/gitmastery-apt-repo any main"
sudo apt update
sudo apt-get install gitmastery

Install using pacman:

sudo pacman -Syu gitmastery-bin

If you are using a Linux distribution that is not yet supported by Git-Mastery, please download the right binary for your architecture from the latest release.

Install it to /usr/bin to access the binary, the following using version 3.3.0 as an example.

install -D -m 0755 gitmastery-3.3.0-linux-arm64 /usr/bin/gitmastery


2. To verify the installation, run the gitmastery --help command from a couple of different folder locations.

gitmastery --help
cd ../my-projects  # cd into a different folder
gitmastery --help

The current version of the app takes about 3-5 seconds to respond to a command. This is because the app comes with a bundled Python runtime (so that users don't need to install Python first) which needs to load first before the command can be executed.

3. Trigger the initial setup by running the gitmastery setup command in a suitable folder (the app will create files/folders inside this folder).

mkdir gitmastery-home
cd gitmastery-home
gitmastery setup

The gitmastery setup command will perform the following tasks:

  • Checks if Git is installed.
  • Checks if user.name and user.email are set.
  • Prompts you to specify a name for the git-mastery exercises directory -- you can accept the default.
  • Sets up a mechanism to locally track the progress of your exercises.

Notes:

  • If the command failed due to checks (a) or (b) failing, you can rectify the problem and run the command again.
  • If you wish to check the Git set up again at a later time, you can run the gitmastery check git command.