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.
Many Linux vendors provide precompiled, binary packages to make the 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. Prior to the 12.04 release, the primary Git package was called git-core. As of the 12.04 release, it is simply called git, and the documentation is available in git-doc. There are other packages to consider, too.
If you need to transfer a project from Arch, CVS, or SVN to Git or vice versa, install one or more of these packages.
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.
This is an essential component if you want to send Git patches through electronic mail, which is a common practice in some projects.
To share your repository, install this package. It creates a daemon service that allows you to share your repositories through anonymous download requests.
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.
This command installs the important Git packages by running apt-get as root.
$ sudo apt-get install git git-doc gitweb
git-gui gitk git-email git-svn
To install Git on other Linux distributions, find the appropriate package or packages and use the distribution’s native package manager to install the software.
For example, on Gentoo systems, use emerge.
$ sudo emerge dev-util/git
$ sudo yum install git
The Fedora git is roughly equivalent to
Debian’s git. Other i386
Fedora packages include:
The core Git tools
A meta-package 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 SVN 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 pub/scm/git directory.
The version of Git described in this book is roughly 1.7.9, but you might want to download the latest revision of the source. You can find a list of all the available versions at http://code.google.com/p/git-core/downloads/list.
To begin the build, download the source code for version 1.7.9 (or later) and unpack it.
$wget http://git-core.googlecode.com/files/git-1.7.9.tar.gz
$tar xzf git-1.7.9.tar.gz
$cd git-1.7.9
Git is similar to other pieces of open source software. Just configure it, type make, and install it. Small matter of software, right? Perhaps.
If your system has the proper libraries and a robust build environment and if you do not need to customize Git, then 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, then you should 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 INSTALL file in the Git source bundle. The file lists several external dependencies, including the zlib, openssl, and libcurl libraries.
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.
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 Makefile and configuration options offer
alternatives. For example, if you lack the expat
library, you can set the NO_EXPAT
option in the Makefile.
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
transports.
Other 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 INSTALL file.
Once your system and build options are ready, the rest is easy. By default, Git is installed in your home directory in subdirectories ~/bin/, ~/lib/, and ~/share/. In general, this default is useful only if you’re using Git personally and don’t need to share it with other users.
These commands build and install Git in your home directory.
$cd git-1.7.9
$./configure
$make all
$make install
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.
$cd git-1.7.9
$./configure --prefix=/usr/local
$make all
$sudo make install
To install the Git documentation, add the doc
and install-doc
targets to the make and make
install commands, respectively.
$cd git-1.7.9
$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.
A build from source includes all the Git subpackages and commands, such as git-email and gitk. There is no need to build or install those utilities independently.
There are two competing Git packages for Windows: a Cygwin-based Git and a “native” version called msysGit.
Both versions work well and support an almost identical set of features. 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”), then 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 obtain the latest version (1.7.10 or higher) because 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.
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).
As an alternative, if your Cygwin configuration includes the various compiler tools like gcc and make, then 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 Secure Shell (SSH) commands to generate the keys that repository maintainers require to control access. msysGit is designed to integrate well with Windows-style native applications (such as the Windows Explorer shell).
First, download the latest version of the installer from its home at http://msysgit.github.com. The file to collect is usually called something like Git-1.8.3-preview20130601.exe.
After the download completes, run the installer. You should see a screen that looks something like Figure 2-3.
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. 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. The best way to run msysGit on a daily basis 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 called Git
.
Because most of the examples in this book use the command line, use
Git Bash to get started.
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 Git Command Line of Chapter 3. To follow the examples with msysGit, enter git-add for git add.
3.143.4.181