Installing Git: Chapter 2 - Version Control with Gitby Jon Loeliger
At the time of this writing, Git is (seemingly) not installed by default on any GNU/Linux distribution or any other operating system. So, before you can use Git, you must install it. The steps to install Git depend greatly on the vendor and version of your operating system. This chapter describes how to install Git on Linux and Microsoft Windows and within Cygwin.
This excerpt is from Version Control with Git. Git permits practically an infinite variety of methods for development and collaboration, but its flexibility also means that some users don't understand how to use it to best advantage. This book offers tutorials on ways to use it, as well as friendly yet rigorous advice to help you navigate Git's many functions.
Many Linux vendors provide pre-compiled, binary packages to make installation of new applications, tools, and utilities easy. Each package specifies its dependencies, and the distribution’s package manager typically installs the prerequisites and the desired package in one (well-orchestrated and automated) fell swoop.
On most Debian and Ubuntu systems, Git is offered as a collection of packages, where each package can be installed independently depending on your needs. The primary Git package is called git-core, documentation is available in git-doc, and there are other packages to consider, too:
- git-arch, git-cvs, git-svn
- git-gui, gitk, gitweb
If you prefer to browse repositories in a graphical application or your Web browser, install these as appropriate. git-gui is a Tcl/Tk-based graphical user interface for Git; gitk is another Git browser written in Tcl/Tk but focuses more on visualizing project history. gitweb is written in Perl and displays a Git repository in a browser window.
Because distributions vary greatly, it’s best to search your distribution’s package depot for a complete list of Git-related packages. git-doc and git-email are strongly recommended.
Debian and Ubuntu provide a package named git, but it isn’t a part of the Git version control system discussed in this book. git is a completely different program called GNU Interactive Tools. Be careful not to install the wrong package by accident!
This command installs the important Git packages by running apt-get as the root:
sudo apt-get install git-core git-doc gitweb \
git-gui gitk git-email git-svn
sudo emerge dev-util/git
sudo yum install git
The Fedora git is roughly equivalent to
Debian’s git-core. Other
Fedora packages include:
The core git tools
A metapackage for pulling in all Git tools
Git tools for importing Arch repositories
Git tools for importing CVS repositories
The Git protocol daemon
Debug information for package Git
Git tools for sending email
Git GUI tool
Git tools for importing Subversion repositories
Git revision tree visualizer
Again, be mindful that, like Debian, some distributions may split the Git release among many different packages. If your system lacks a particular Git command, you may need to install an additional package.
Be sure to verify that your distribution’s Git packages are sufficiently up-to-date. After Git is installed on your system, run git --version. If your collaborators use a more modern version of Git, you may have to replace your distribution’s precompiled Git packages with a build of your own. Consult your package manager documentation to learn how to remove previously installed packages; proceed to the next section to learn how to build Git from source.
If you prefer to download the Git code from its canonical
source or if you want the latest version of Git, visit Git’s master
repository. As of this writing, the master repository for Git sources is
http://git.kernel.org in the
The version of Git described in this book is roughly 1.6.0, but you might want to download the latest revision of the source. You can find a list of all the available versions at http://kernel.org/pub/software/scm/git.
To begin the build, download the source code for version 1.6.0 (or later) and unpack it:
tar xzf git-1.6.0.tar.gz$
If your system has the proper libraries and a robust build environment and you do not need to customize Git, building the code can be a snap. On the other hand, if your machine lacks a compiler or a suite of server and software development libraries, or if you’ve never built a complex application from source, consider building Git from scratch only as a last resort. Git is highly configurable, and building it shouldn’t be taken lightly.
To continue the build, consult the
file in the Git source bundle. The file lists several external
dependencies, including the
Some of the requisite libraries and packages are a bit obscure or belong to larger packages. Here are three tips for a Debian stable distribution:
curl-config, a small tool to extract information about the local
curlinstall, can be found in the libcurl3-openssl-dev package.
The header file
expat.hcomes from the libexpat1-dev package.
msgfmtutility belongs to the gettext package.
Because compiling from sources is considered “development” work, the normal binary versions of installed libraries are not sufficient. Instead, you need the -dev versions because the development variants also supply header files required during compilation.
If you are unable to locate some of these packages or cannot find
a necessary library on your system, the
and configuration options offer alternatives. For example, if you lack
the expat library, you can set the
NO_EXPAT option in the
However, your build will lack some features, as noted in the
Makefile. For example, you will not be able to push
changes to a remote repository using the HTTP and HTTPS
Makefile configuration options support
ports to various platforms and distributions. For instance, several
flags pertain to Mac OS X’s Darwin operating system. Either hand-modify
and select the appropriate options or find what parameters are set
automatically in the top-level
Once your system and build options are ready, the rest is easy. By
default, Git is installed in your home directory in subdirectories
~/share/. In general, this default is useful only
if you’re using Git personally and don’t need to share it with other
These commands build and install Git in your home directory:
If you want to install Git into an alternate location, such as
/usr/local/ to provide general access, add
--prefix=/usr/local to the
./configure command. To continue, run
make as a normal user, but run make
install as root:
sudo make install
To install the Git documentation, add the
install-doc targets to the
make and make install commands,
make all doc$
sudo make install install-doc
Several more libraries are needed to do a complete build of the documentation. As an alternative, prebuilt manpages and HTML pages are available and can be installed separately as well; just be careful to avoid version mismatch problems if you choose to go this route.
Originally, only the Cygwin version was supported and msysGit was experimental and unstable. But as this book went to press, both versions work well and support an almost identical set of features. The most important exception, as of Git 1.6.0, is that msysGit does not yet properly support git-svn. If you need interoperability between Git and Subversion, you must use the Cygwin version of Git. Otherwise, the version you choose is a matter of personal preference.
If you aren’t sure which one you want, here are some rules of thumb:
If you use Cygwin already on Windows, use Cygwin’s Git because it interoperates better with your Cygwin setup. For example, all your Cygwin-style filenames will work in Git, and redirecting program input and output will always work exactly as expected.
If you don’t use Cygwin, it’s easier to install msysGit because it has its own standalone installer.
If you want Git integration with the Windows Explorer shell (for example, the ability to right-click on a folder and pick “Git GUI Here” or “Git Bash Here”), install msysGit. If you want this feature but prefer to use Cygwin, you can install both packages without harm.
If you’re still in doubt about which package to use, install msysGit. Make sure you get the latest version (126.96.36.199 or higher), as the quality of Git’s Windows support steadily improves in successive versions.
The Cygwin Git package, as the name implies, is a package inside the Cygwin system itself. To install it, run Cygwin’s setup.exe program, which you can download from http://cygwin.com.
After setup.exe launches, use the default settings for most options until you get to the list of packages to install. The Git packages are in the devel category, as shown in Figure 2.1, “Cygwin setup”.
After choosing the packages you want to install, click Next a few more times until the Cygwin installation finishes. You can then start the Cygwin Bash Shell from your Start menu, which should now include the git command (Figure 2.2, “Cygwin shell”).
As an alternative, if your Cygwin configuration includes the various compiler tools like gcc and make, you can build your own copy of Git from source code on Windows under Cygwin by following the same instructions as on Linux.
The msysGit package is easy to install on a Windows system because the package includes all its dependencies. It even has SSH commands to generate the keys that repository maintainers require to control access. msysGit is designed to integrate well with the Windows-style native applications such as the Windows Explorer shell.
First, download the latest version of the installer from its
home at http://code.google.com/p/msysgit. The
file to collect is usually called something like the following:
After the download completes, run the installer. You should see a screen that looks something like Figure 2.3, “msysGit setup”.
Depending on the actual version being installed, you may or may not need to click Next through a compatibility notice as shown in Figure 2.4, “msysGit notice”. This notice concerns incompatibilities between Windows-style and Unix-style line endings, called CRLF and LF, respectively.
Click Next a few more times until you see the screen shown in Figure 2.5, “msysGit choices”.
The best way to run msysGit day-to-day is via Windows Explorer, so check the two pertinent boxes, as shown.
In addition, an icon to start Git
Bash (a command prompt that makes the git
commands available) is installed in the Start menu in the section
Git. Since most of the examples in this book
use the command line, use Git Bash to get
All the examples in this book work equally well on Linux and Windows, with one caveat: msysGit for Windows uses the older Git command names mentioned in the section called “The Git Command Line”. To follow the examples with msysGit, enter git-add for git add.
If you enjoyed this excerpt, buy a copy of Version Control with Git.