Installation and setup
In this section, we will learn how to install and configure Git.
Installing Git on your machine
Install Git from the official website.
Install Git for Windows. This will also install Git Bash, a Bash emulator.
Git is built for Unix-like systems (Linux and macOS). In order to use Git from the command line on Windows, you need a Unix shell such as Bash. To make this very easy, Git for Windows comes with its Bash emulator.
Git on the Alliance clusters
On the Alliance clusters, Git is not only already installed, but it gets automatically loaded at each session, so you don’t have to load a module for it (as you do for most software). This is because Git is an integral part of any good workflow.
Using Git
For this workshop
We will use Git from the command line throughout this workshop:
Linux users:
macOS users:
Windows users:
open the terminal emulator of your choice.
open the application called ‘Terminal’.
open the application called ‘Git Bash’.
Why the command line?
There are very friendly GUIs (graphical user interfaces) software for Git, but there are many good reasons to learn how to use Git from the command line:
- GUI software tend to be buggy,
- they are limited to simple operations and you can’t use Git to its full potential with them,
- when you work on a remote machine (e.g. on the Alliance clusters), using Git from the command line is so much more convenient,
- there will be situations in your life when you will not have access to your favourite Git GUI software and you will have to use the command line, so you need to know how to use it, even if this is not what you will do in your every day workflow.
Other ways to run Git
Another (and great!) way to use Git is with the TUI called lazygit which I will describe in a later section. I also gave a webinar on it that you can watch after this course.
Git is also increasingly integrated into IDEs (e.g. RStudio, Jupyter, VS Code). Note that you might not be able to perform less routine Git operations via these interfaces and you might have to go back to the command line on occasions (lazygit does it all).
Configuring Git
Before you can use Git, you need to set some basic configuration. You will do this in the terminal you just opened.
List settings
git config --listUser identity
git config --global user.name "<Your Name>"
git config --global user.email "<your@email>"Example:
git config --global user.name "John Doe"
git config --global user.email "john.doe@gmail.com"It is recommended to use your real name and real email address: when you will collaborate on projects, you will probably want this information to be attached to your commits rather than a weird pseudo.
Text editor
git config --global core.editor "<text-editor>"Example for nano:
git config --global core.editor "nano"Line ending
macOS, Linux, or WSL
git config --global core.autocrlf inputWindows
git config --global core.autocrlf trueData integration method
When you pull from a remote that was changed by a collaborator, their changes need to be integrated into yours. There are two ways to do this: with and without rebase.
To save you from having to pass the --rebase or --no-rebase flag each time you run git pull, you can set our preference in the configuration file.
To use the non-rebase method (which used to be the default in older versions of Git), run:
git config --global pull.rebase falseThis will integrate changes from remote branches into your local branches by creating merge commits.
If you want to use rebase instead, run the above line with true.
In that case, the commits from the remote branch would be inserted before your local commits, thus creating a linear history and preventing the creating of merge commits.
You can look at this blog post for a good summary of the pros and cons of each method.
Project-specific configuration
You can also set project-specific configurations (e.g. maybe you want to use a different email address for a certain project).
In that case, navigate to your project and run the command without the --global flag.
Example:
cd /path/to/project
git config user.email "your_other@email"