Git is a version control system that lets you track who made changes to what when and has options for easily updating a shared or public version of your code on source code repository hosting platforms such as GitHub or GitLab or Bitbucket. You will need a supported web browser (current versions of Chrome, Firefox, Safari, or Internet Explorer version 9 or above).
You will need an account at GitHub for parts of the Git lesson. Basic GitHub accounts are free. We recommend you to create a GitHub account if you don’t have one already. Please consider what personal information you’d like to reveal. For example, you may want to review these instructions for keeping your email address private provided at GitHub.
If you do not wish to use GitHub and a corresponding account, you can instead use your favourite source code repository hosting platform. Most aspects of our material and exercises are transferable to all popular platforms.
Follow the installation instructions below but do not forget to also configure Git.
Conda can be used to install Git on Linux, macOS and Windows computers. To install Git without conda, please follow the instructions in the following sections.
To install Git with conda, you need to have installed Anaconda or Miniconda. Then you can install Git in one line in the Anaconda prompt (on Windows) or in a terminal (macOS and Linux):
$ conda install git
On Windows, this will guarantee that you can use both Git and Python and Anaconda scripts in the same (conda) environment.
If Git is not already available on your machine you can try to install it via your distribution package manager.
For Debian/Ubuntu run:
$ sudo apt-get install git
Check the version after installing:
$ git --version
$ sudo dnf install git
Install Git for Mac by downloading and running the most recent “mavericks” installer from this list.
After installing Git, there will not be anything in your
folder, as Git is a command line program.
Use the most recent available installer labelled “snow-leopard” available here.
In this case Git should be installed on your computer as part of the Bash installation.
Possible problem with this approach is that Git Bash does not see the Python and Anaconda scripts. See also the troubleshooting page.
After signing up for a GitHub account and installing Git on your machine, you should go through the following steps to configure Git. First, the following commands will set your user name and email address:
$ git config --global user.name "Your Name" $ git config --global user.email email@example.com
If you are unsure which email to use, use the one that you have registered at GitHub with.
If you prefer to not use a real email address but still want to make sure that GitHub
counts your contributions, you can use
This is important since your Git commits use this information.
--global option ensures that you do not need to enter this information again on your machine.
It is important to set also the default text editor to use with Git. You can replace nano with vim, emacs or any other editor of your choice:
$ git config --global core.editor nano
If you use Atom as editor, set:
$ git config --global core.editor "atom -nw"
If you are on Windows and want to use Notepad or Notepad++, you can configure this by providing the full path to the executable and optionally set some options. For example (adjust the path if needed, and note the quotation):
$ git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
To see where this information is stored (
--show-origin works on git version 2.8.0 or greater only), use:
$ git config --list --show-origin
Create a new example folder, step into it, then create a file
Initialize a repository and stage the new file:
$ git init $ git add example.txt
Commit the change, this should open the editor which you have configured, in there add an example commit message:
$ git commit example.txt
$ git log
If you see now something line this (different name, email, and commit message), your Git is configured for the workshop:
$ git log commit 12e4cb892140bd14a413895b3b36c27db198eb22 (HEAD -> master) Author: Radovan Bast <firstname.lastname@example.org> Date: Fri May 15 16:41:13 2020 +0200 making a test commit
Using the SSH protocol, you can connect and authenticate to remote servers and services. With SSH keys, you can connect to GitHub without supplying your username or password at each visit.
If you are unsure about this, you can skip this part and authenticate with GitHub using your username and password every time you will push changes to GitHub.
If you decide to set up SSH keys, follow this guide to connect to GitHub with SSH keys.