Installing Git

Git is open source, free, and is available for easy installation on a range of operating systems, including Windows, macOS and Linux.

You will need to have installed the command line version control tool “git”. The instructions below tell you how to install it on each of these platforms.

Command Line Interface

If you don’t have experience working with a Command Line Interface, you can check the training course Introduction to the Command Line Interface.

Windows

You can install git by downloading an installer from https://git-scm.com/download/win.

Once you have downloaded the installer, double click on the downloaded file to execute it. Follow the instructions of the installer (click “Next” to accept the license etc.). Make sure that everything associated with Git Bash is enabled, and “Use Git from Git Bash only” is selected.

Alternatively, if you are using Anaconda, you can install git from the command line:

conda install -c anaconda git

macOS

On macOS, you have several choices for how you install git.

  1. You can use the git that is installed as part of Xcode (Apple’s free development environment that is supplied as a separate download for macOS).

  2. Install git by going to the official git website and choose macOS.

Linux

Please install Git using your package manager, e.g. following the instructions here. The exact command you type will depend on your Linux distribution. Typically, the command will look like apt-get install git, or yum install git, or dnf install git.

Starting Git

Once you have installed git, you now need to start a command window. On Windows, you do this by starting Git Bash. On Linux or macOS you need to open a command window (e.g. also called a “terminal”, “bash window”, “console”).

To check that git is working, please type the following in the command window and press return;

git --version

This should run the git command, and will print the version number of git to the screen. For example, on my Mac, I see this printed;

git version 2.24.3 (Apple Git-128)

If you see something like this printed;

command not found: git

then that means that git is not installed, or something is wrong. Please go through the installation instructions again and double-check you have followed all steps.

Choosing a text editor

We will also need to use a text editor. A text editor is a program that lets you create and edit simple text files. There are many different text editors available. You are free to choose the one you like the best. Commonly-installed text editors include;

  • nano - this is a good text editor for beginners (and my favorite and personal choice). It should be installed by default on macOS and Git Bash on Windows.

  • vim - this is a standard text editor that is installed nearly everywhere, and is definitely available on all platforms. This is a more complex text editor to use, and is not recommended for beginners.

  • notepad++ - this is a graphic text editor for Windows. This is very easy for beginners to use, but is not available for macOS or Linux.

Configuring Git

The first thing you have to do when using Git for the first time on a computer is to tell Git who you are. This will allow Git to keep a record of who owns or changes the files that it will manage.

Tell Git your name using the command

git config --global user.name "Your Full Name"

where "Your Full Name" is your full name, e.g. for me I would type

git config --global user.name "Jean Golding"

Next you need to give Git your email address. Do this using the command

git config --global user.email "Your Email Address"

where "Your Email Address" is your email address, e.g. for me I would type

git config --global user.email "ab01234@bristol.ac.uk"

Finally, you should tell Git which text editor you want to use when it asks you to enter extra information. This should be the text editor that you installed in the last section. You do this using the command

git config --global core.editor "Your text editor"

I prefer to use nano, so for me I would type

git config --global core.editor "nano"

(note, on Windows if you want to use notepad++ that you will need to type in the full path to the executable, e.g. git config --global core.editor "C:\Program Files (x86)\Notepad++\notepad++.exe")

You only need to type the above commands once, the first time that you use git on a new computer. These options are saved and are then used every time you use git. You can change these at any time just by running the commands again. You can also see the current value of these variables by typing the command without the value, e.g.

git config --global user.name

will print

Jean Golding

Note also that this information is stored privately on your computer. Your email address and name won’t be shared publicly yet. This information will only be shared if you back up to a cloud service, such as GitHub (see later in this workshop). You don’t need to use real information, and can use a dummy email address or name alias if you want.