© Mariot Tsitoara  2020
M. TsitoaraBeginning Git and GitHubhttps://doi.org/10.1007/978-1-4842-5313-7_2

2. Installation and Setup

Mariot Tsitoara1 
(1)
Antananarivo, Madagascar
 

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.

You can also see in Figure 2-1 that there are GUI clients for Git also available there. Don’t head out there before you complete this book’s third part, Teamwork with Git. You need to familiarize yourself with Git commands before using GUI clients; if not, you will lose a lot of time trying to resolve a simple issue that would take seconds with simple Git commands.
../images/484631_1_En_2_Chapter/484631_1_En_2_Fig1_HTML.jpg
Figure 2-1

The download section of git-scm.com as of May 2019

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

Installing Git on Windows systems is very easy. After opening the link (https://git-scm.com/download/win), the download should automatically begin, and you will arrive at the confirmation page shown in Figure 2-2. If not, just download the build that corresponds to your Windows flavor.
../images/484631_1_En_2_Chapter/484631_1_En_2_Fig2_HTML.jpg
Figure 2-2

The Git download screen for Windows

Execute the download exe file to begin the installation. The first screen is the license declaration outlining the terms and conditions; you should read it until the end (yeah, right). Click next, and you will get to a component selection screen similar to the one shown in Figure 2-3. Here, you are prompted to select which components to install. I recommend to leave the default options on.
../images/484631_1_En_2_Chapter/484631_1_En_2_Fig3_HTML.jpg
Figure 2-3

Select the components to install

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.

Click next after you made your choices, and you will see the default editor selection, shown in Figure 2-4. Git needs you to define a default editor because you need an editor to write out commit descriptions and comments.
../images/484631_1_En_2_Chapter/484631_1_En_2_Fig4_HTML.jpg
Figure 2-4

Default editor selection

As you can see in Figure 2-4, Vim is the default editor for Git for historical reason. Just pick your favorite text editor from the dropdown list. The first two, Nano and Vim, work in the console or command window, so you don’t have to open another program. In the list, you can find many popular editors like Notepad++, Sublime Text, Atom and Visual Studio (VS) Code. If your editor isn’t listed, you can choose the last option, and a new input will appear (shown in Figure 2-5) so you can provide a link to the editor’s main executable file.
../images/484631_1_En_2_Chapter/484631_1_En_2_Fig5_HTML.jpg
Figure 2-5

Setting up a custom editor

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.

Once you chose your favorite editor, you can go to the next screen, which is the PATH environment adjustment, shown in Figure 2-6. The PATH environment is a variable that holds a list of directories where executable programs are located in their value. It’s needed so you don’t have to type in the full path to an executable when you want to execute it in the console; you just have to type its name. For example, to launch Visual Studio Code from the console, I should type C:Program Files (x86)Microsoft VS Codeincode. But since I have C:Program Files (x86)Microsoft VS Codein in my PATH, I just have to type “code” to launch it.
../images/484631_1_En_2_Chapter/484631_1_En_2_Fig6_HTML.jpg
Figure 2-6

Choosing to add Git to PATH or not

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.

Choose an option as shown in Figure 2-6 and proceed to the next step. You will arrive at a screen concerning HTTPS connections, shown in Figure 2-7. You will have to choose which library to use when sending data over HTTPS. Later in this book, you will have to connect to a remote server (since Git is a distributed VCS) to share your commits to other people, so all those connections must be encrypted to further secure your data and ensure they are not being stolen.
../images/484631_1_En_2_Chapter/484631_1_En_2_Fig7_HTML.jpg
Figure 2-7

Choosing the HTTPS transport

Just use the default option unless you have a reason to (company policy or your own little security setup).

After this, go to the next step which is about line endings. Once again, it’s a selection screen, so yours should look like the one shown in Figure 2-8. Different Operating Systems operate text files differently, especially when dealing with line endings. And odds are that the team you will be working with will be using different OS. So, Git needs to convert line endings to and from each ending style before sharing commits.
../images/484631_1_En_2_Chapter/484631_1_En_2_Fig8_HTML.jpg
Figure 2-8

Line ending conversions

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.

The next step is to choose a default terminal (or console) emulator. It’s a simple selection screen like before, shown in Figure 2-9. Git Bash needs a console emulator to work, so you need to choose one. The default emulator is MinTTY, the other option being Windows’ default console.
../images/484631_1_En_2_Chapter/484631_1_En_2_Fig9_HTML.jpg
Figure 2-9

Choosing a terminal emulator

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.

We are now in the endgame! This installation is nearly over. Just a few things to tweak in the extra options screen. This screen (shown in Figure 2-10) permits you to enable some extra features that will go great with your Git installation. For example, the Git Credential Manager will help you connect to remote servers securely and plays nicely with other Git tools.
../images/484631_1_En_2_Chapter/484631_1_En_2_Fig10_HTML.jpg
Figure 2-10

Configuring extra options

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

If you’ve already done some software development with Mac OS X, you probably already have Git because it’s installed with XCode (https://developer.apple.com/xcode/). You can check if you have Git by running the command from your console:
$ git --version

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.

To install Git on your Mac, you just have to go to the download link https://git-scm.com/download/mac, and the download should begin automatically, as shown in Figure 2-11. Execute the downloaded file and the installation will start; it’s pretty easy.
../images/484631_1_En_2_Chapter/484631_1_En_2_Fig11_HTML.jpg
Figure 2-11

Download screen for Mac

You can also use Homebrew (https://brew.sh/) to install it. Just run the command:
$ brew install git

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.

For Ubuntu- and Debian-flavored distributions, you use APT to install Git.
$ sudo apt-get install git
or
$ sudo apt install git (for newer systems)
For Fedora, you can use YUM or DNF.
$ sudo yum install git
or
$ sudo dnf install git (for newer systems)
If you have a different distribution, you can check https://git-scm.com/download/linux to have a list of commands on how to install Git for each popular distro. This list should be similar to the one shown in Figure 2-12, with more and more Linux flavors to come.
../images/484631_1_En_2_Chapter/484631_1_En_2_Fig12_HTML.jpg
Figure 2-12

How to install Git on Linux

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!

To set up Git, open Git Bash (for Windows systems) or the default console window (for Linux/MacOS or Windows systems that modified their PATH environment). In the command prompt, just tell Git your name and email address:
$ git config --global user.name "Mariot Tsitoara"
$ git config --global user.email "[email protected]"

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.

With the config command, you can also change your default editor. If you ever want to change your editor because you found a new one or uninstalled yours, the config command is there to help you. For example, to change the default editor to Nano, you would type
$ git config --global core.editor="nano"
You can find the file recording your Git configuration on your home folder. For Windows, you can find it in C:UsersYourName.gitconfig. For Linux and Mac OS, you can find it in /home/yourname/.gitconfig as shown in Figure 2-13.
../images/484631_1_En_2_Chapter/484631_1_En_2_Fig13_HTML.jpg
Figure 2-13

My .gitconfig file

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.143.181