We have already seen What is Git? and understand what it’s for. But to start using it, we first (logically) need to set up our working environment.
In this entry, we are going to install Git on our computer and perform the mandatory initial configuration.
Console or GUI?
The million-dollar question: Is it better to use Git from the terminal or from a graphical interface (GUI)?
Some “purists” will tell you that you should only use the console. Others prefer the convenience of buttons and graphics.
In my opinion, the best thing you can do is learn to use both, and that’s how we’ll do it in the course.
✔️ When to use the command line
It’s useful for understanding what’s really happening and especially for fixing complex problems.
✔️ When to use a GUI or an IDE
It’s useful for day-to-day tasks, for seeing differences between files, reviewing history, and resolving merge conflicts.
Installing Git
In any case, whether we use the console or a graphical interface, the first step is to have the Git engine installed and configured (the configuration is best done in the console).
The installation varies slightly depending on your operating system.
On Windows, the standard way to install Git is through the official installer.
Go to the official website git-scm.com
Download the “Standalone Installer” version (32 or 64 bits depending on your computer)
Run the installer
The Windows installer asks many questions. For most users, the default option works fine, but I recommend you pay attention to:
- Adjusting your PATH environment: Make sure to select “Git from the command line and also from 3rd-party software”
Git is in the official repositories of almost all distributions.
For Debian / Ubuntu and derivatives:
sudo apt-get update
sudo apt-get install git
For Fedora / RHEL / CentOS:
sudo dnf install git
The recommended option for having more up-to-date and manageable versions is to use Homebrew:
brew install git
Verification
Whatever your system, open a terminal and type the following to confirm everything went well:
git --version
You should see something like git version 2.40.0 (or higher).
Initial Configuration
Once installed, you can’t start working yet. Git needs to know who you are, and some other optional configuration.
Mandatory
Open your terminal and run these two commands (changing the data to yours):
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
The email you put here will be public in the history of any project you collaborate on and upload to GitHub/GitLab.
Optional
When Git needs you to write a message (for example, when making a commit without a message or merging branches), it will open a text editor.
By default, it usually opens Vim. Vim is a very powerful editor, but if you don’t know how to use it, you’ll get stuck in it without knowing how to exit (spoiler: it’s :q!).
To avoid panic, configure an editor you are comfortable with. If you use VS Code:
git config --global core.editor "code --wait"
The --wait flag tells the terminal to wait for you to close the VS Code window before continuing.
Optional
Historically, the main branch was called master. For a few years now, the community and platforms like GitHub have migrated to the name main.
To make your new repositories be born directly with main and avoid discrepancies:
git config --global init.defaultBranch main
Optional
This is a technical topic but very important if you work in a team with people from Windows and Mac/Linux at the same time.
- Windows uses two characters for line breaks: Carriage Return + Line Feed (
\r\nor CRLF). - Mac/Linux use only one: Line Feed (
\nor LF).
If we don’t control this, commits will be filled with “invisible” changes just because someone saved the file on Windows.
To fix this, we tell Git to handle this automatically:
If you are on Windows: Configure Git to convert to LF when saving to the repo, but convert to CRLF when downloading files to your disk.
git config --global core.autocrlf true
If you are on Mac / Linux: Configure Git to convert to LF when saving (just in case), but do nothing when downloading (because your system already uses LF).
git config --global core.autocrlf input
Every snapshot (commit) made in Git has the author’s name and email embedded. This information is immutable once the commit is created.
Checking Your Configuration
To see if you have configured everything correctly, you can ask Git for a list of your current configuration:
git config --list
You will see a list with all the variables we just defined.
We now have Git installed and configured. We have the “engine running”. In the next article, we will create our first repository and start managing our files.
