Now that you how what is Version Control and how Git works, we are going to learn how to install and set it up. This chapter is shorter compared to the others because it is so easy to set Git up.
Installation
The files necessary to install Git are on https://git-scm.com/downloads for all systems. Just follow the link and choose your Operating System.
After you have familiarized yourself with Git commands, you can check out a GUI client and see for yourself. There is a chapter about GUI clients at the last part of this book. But please don’t use any GUI client before that time; it will greatly lengthen your learning time.
Note
Git is bundled with two GUI tools: gitk to review history and git-gui for basic commands. You will learn to use them in the last part of this book, so the preceding advice still applies.
Windows
You can see in Figure 2-3 that you just have to check the components to install them. It is a good idea to leave the Windows Explorer integration checked; that way you would just have to right-click a folder to find the options to start Git in the default GUI or the Bash (command window) in the context menu. All the other components are pretty self-explanatory so the decision is up to you.
Tip
If you didn’t install the Windows Explorer integration and want to open the command window in a folder, you have to open the extended context menu with Shift + Right-click.
In Figure 2-5, you can see the screen where you can set up your custom editor if it isn’t listed on the dropdown.
For this book, I decided to leave the default option and use Vim. It doesn’t change anything in this book if you decide to use any other editor. But if you want to learn Vim (takes a bit of time), you can check out “vimtutor,” which is a tutor program shipped with Vim, or learn through a fun video game on https://vim-adventures.com/. There is also www.vi-improved.org/vimusermanual.pdf which is more complete but is more than 300 pages!
And don’t worry, this choice is not definitive, you can still change anytime you want. You will learn how at the last section of this chapter.
Caution
While online, never ever start or participate in an Editor War. Just choose your preferred text editor and never talk about it to anyone. I still bear scars from my old days in the “Emacs vs. Vim” war.
The same could apply to Git if you want. If you don’t want this and only want to use Git with its own isolated console “Git Bash,” select the first option. So, to use Git, you would have to launch it from the Apps list or from the context menu of a folder (if you chose to install the Windows Explorer integration).
If you want to be able to use Git everywhere, leave the default option to add it to your PATH environment. That way, other tools can also use Git and you can work from any command window. I highly suggest this option.
The last option is a bit invasive. It will add many Git commands to your PATH and will overwrite some of Windows’ default tools. Only choose this if you have a valid reason too; generally, you don’t have such a reason.
Just use the default option unless you have a reason to (company policy or your own little security setup).
As you will be using Windows, you should check the default option. The other two options will do a lot of damage to your commits if you are not careful with line endings. You can go to next step after choosing the default option.
Caution
This step is important because Windows and MacOS use to end lines instead of Linux’s . If you don’t convert, your file will become very hard to read and Git will detect a lot of changes even if didn’t make that many.
I suggest keeping the default option because MinTTY can do everything that the Windows console window can, but better in every way. Click next to proceed to the last step.
Just leave the default options unless you have a reason not to. After that, just launch the installation and let it finish. And that’s it! Git is installed on your Windows system. But before using it, jump to the next section to properly set it up!
Mac
It should give you the version of Git currently installed or if it’s not installed prompt you to install XCode’s Command Line Tools. If you choose install on that prompt, Git will be installed and you can skip the rest of this section.
This will install about half the universe, but it will eventually stop, and Git will be installed.
And that’s it! For Mac OS X, installing Git is way easier and you probably already have it.
Linux
If you use Linux regularly, you probably know much about your distribution than me. So, installing Git with your package manager might be a piece of cake for you.
After you use the command corresponding to your distribution listed in Figure 2-12, Git is installed!
Caution
Just like Editor War, Distribution War is a big no-no online.
Setting up Git
Before beginning to use Git, you need a little bit of setup first. You will probably only do this once since all the setup is stored on an external global file, meaning that all your projects will share the same configs. There is also a way to configure projects one by one but we will see this later.
Since Git is a distributed Version Control System, you will one day need to connect to other remote repositories. To avoid making any identity mistake, it is necessary to tell Git a bit about yourself. Don’t worry; it won’t ask about a fun fact about you!
Notice the “global” argument; it means that the setup is for all future Git repositories, so you don’t have to set this up again in the future.
Next to the .gitconfig file, you might find another file called .bash_history that records all the commands you type on the console. You can check this document if you want to check back on a command you forgot.
Summary
Let’s review what we’ve learned so far! First, you should have had Git installed on your system by now. The installation process is very easy on Windows and easier on Mac and Linux. I suggest you keep all the default options (even if they aren’t shown in the preceding screenshots) if you are not sure of what you need.
Next, there is the setup. You will only have to do this once in every system you install Git into. Git will use your name and email to sign every action you make so it’s necessary to set them up before you using it.
And that’s it! You are now ready to use Git with all its glory. Head to the next chapter to jump start with Git.