What is git?
Git is a distributed version control system created to support the development of a Linux kernel. It was started in April 2005 by Linus Torvalds and is now maintained by Junio C. Hamano.
The main features that set git apart among other version control systems are:
- Data integrity
- Distributed system
- Open source
- Last but not least—popularity
Because git is a distributed version control system, every repository is fully functional and can serve both as a sender and a receiver. If there is a channel of communication between the computers, their repositories can exchange the contents in both directions. Therefore, you can create more complicated workflows than just the client/server paradigm that are used by centralized revision control systems.
Added to this is the fact that git is an open-source project and it is becoming the most popular version control system on the world—you’ll see that there is good reason to start learning git.
Installing git on Windows
Go to http://msysgit.github.io/ and download the most recent installer version of git for Windows. At the time of writing this was version 1.8.3. The installer was named: Git-1.8.3-preview20130601.exe. Run the installer leaving all options set to default values. After this, git is ready to be run on your system.
How It Works
There are two methods for installing git on Windows:
- Use Cygwin package available at http://www.cygwin.com
- Use the standalone installer called msysgit.
In this procedure we use msysgit package. When you run the msysgit installer downloaded from http://code.google.com/p/msysgit/ you will be asked two questions:
- How to configure the paths?
- How to configure the conversion of end of line character?
The dialog box titled Adjusting your PATH environment sets the path environment variable. Msysgit installer contains not only git binaries but also a number of Linux programs such as ssh, curl, ls, mkdir, rm, and find. With default settings the installer copies git and these programs to the following directories:
C:\Program Files (x86)\Git\bin
This folder contains ls, mkdir, ssh, curl, find, etc.
C:\Program Files (x86)\Git\cmd
This folder contains the git binary file and the shell script to run git
The first choice in the dialog box is Use Git Bash only. With this setting the path variable is not modified. When you start a Windows command line and type git, the command line will respond with a message that the git command does not exist.
The second choice, Run Git from the Windows Command Prompt, adds the C:\Program Files (x86)\Git\cmd folder to your path. Thus, you can use git command in the windows command line. When you type ssh in the windows command line, however, the system will respond with an unknown command message.
The last choice is Run Git and included Unix tools from the Windows Command Prompt. This choice adds two folders C:\Program Files (x86)\Git\bin and C:\Program Files (x86)\Git\cmd to your path. Now, you can use all the included tools in the Windows Command line: ssh, git, ls, curl, and so on. But some commands in C:\Program
Files (x86)\Git\bin, such as find, overlap with the original commands available in Windows. The original find is not available now in the command line.
When I was writing this book my intention was to present the commands that can work in exactly the same way on all platforms. Thus I decided to use the bash command line. If you work on Windows and want to use bash command line, then you can leave the default first choice Use Git Bash only.
The second dialog box, which is titled Configuring the line ending conversions, sets the configuration option named core.autocrlf to one of these values: true, input, or false. The meaning of this setting is summarized in Table below.
|True||LF => CRLF||CRLF => LF|
|input||None||CRLF => LF|
When you choose the first setting, the value true, git will convert the end-of-line characters in your files during the checkout and commit operations. When you check the files out, git will convert LF to CRLF and when you commit git will convert CRLF to LF.
The second choice, input, turns the conversion of new lines only when you commit. In this case git converts the
line endings from CRLF to LF.
The third setting (false) turns all the conversions off.
The conversion of end-of-line characters is explained in greater detail in Recipes 13-2 through 13-6. No matter which is your current choice, you can always change the setting using one of these commands:
$ git config --global core.autocrlf true $ git config --global core.autocrlf input $ git config --global core.autocrlf false
When the installer finishes, run the git bash application available in the Start menu. To verify that the installation was successful, you can run the command:
$ git --version
It should print the version of git installed on your system.