Appendix B. Installing the Latest Version of Git

This book primarily covers the basics in Git, so there aren’t a lot of new features that you’ll be missing out on if you don’t upgrade. In general, I find newer versions of the software to be increasingly more friendly to use. The error messages are clearer, and provide better “next action” suggestions. The syntax of some tricky commands has improved, making the commands easier to remember. (For example, the ability to delete a remote branch using the parameter --delete, and not some weird syntax involving a colon.)

So you think you have Git installed. Sweet!

But the version that ships with your operating system is 90% likely to be 100% old. “It’s all Git to me!” I hear you saying. I know, I know. I used to think the same thing: Git is old and complicated and hasn’t changed in a million Internet years. And then I went to a Git developer conference. At the conference, I met wonderful developers who were friendly and welcoming and patient and funny and very much actively engaged in making Git better. At the time, the maintainer of Git was Junio Hamano, and the Windows maintainer was Johannes Schindelin. They were both at the conference and were genuinely interested in making Git easier for you to use. You won’t see what the community has been up to if you don’t install the latest version!

You should always try to use the latest stable version of software, and you definitely owe it to yourself to ensure you are using at least version 2.5 of Git. As of this version of Git, the command git help is much more useful. I’m very excited about this change as it was one of the things that bugged me about Git from the very first time I used it. Then, at the Git developer conference, I made passing comment, which turned into an unofficial bug report…and a few months later Sébastien Guimmara and Eric Sunshine made my wish into the command you use today. Incredible!

I’m often a few patches out of date (e.g. if the latest version is 2.5.2, I might be on 2.5.0), but I do make a careful effort to stay relatively current. If you don’t remember having installed Git in the last few months, you will almost definitely want to upgrade. You may also need to install Git if it’s not already on your system (it’s not hard! there are installers you can use!).

Installing Git and Upgrading

There are human-friendly Git installers available for Windows and OS X. The installer will generally attempt to keep your settings in place when you upgrade Git.

These installers are available from:

http://git-scm.com/downloads

If you are on Linux or Unix, you probably already have Git installed, but you should upgrade to the latest version. Use your package manager to do this (tips in “Upgrading on *nix Systems”). OS X users may also want to use a package manager to install Git and keep it up to date.

Finding the Command Line

This book is focused on using Git from the command line. I make no apologies about this. There are two critical reasons I think you should give it a try:

  1. It’s easier to copy and paste documentation that works on all operating systems when everyone is working from the command line.

  2. You get better error messages when you’re working from the command line. In a graphical interface it’s harder to copy and paste the sequence of commands you ran right before getting into the pickle you’re now in. By working from the command line, you will be able to get help faster from others when things go wrong.

As you gain comfort with the concepts in this book, I encourage you to transfer that knowledge to graphical interfaces if you prefer.

OS X

  1. Open Spotlight. Spotlight is available from the magnifying glass in the top-right corner of the menu bar, or by pressing Control + Space.

  2. Into the Spotlight search window, type terminal and press Return. A new terminal window will appear.

Linux

The location of a terminal window will vary depending on which distribution of Linux you are using, and the window manager you are using. If you don’t know how to open a terminal window for your version of Linux, a quick search with your favorite search engine should be able to help out.

Windows

The method you use will vary slightly depending on the version of Windows you are running.

Windows 7:

  1. Click the button labeled “Start.”

  2. Select Program Files → Accessories → Command Prompt. A terminal window will open.

Windows 8:

  1. Navigate to the Apps screen (swipe up; or use a mouse and click the down arrow at the bottom of the screen).

  2. Locate the section heading Windows System by swiping or scrolling to the right.

  3. Under Windows System, press or click Command Prompt.

Upgrading on *nix Systems

Package managers are a great way to ensure you are using an up-to-date version of Git on your system. On Linux and Unix-variants, you will upgrade Git using the same package manager that you used to install Git previously (well, Git was probably already installed, and you might have needed to upgrade).

Homebrew Is a Package Manager for OS X.

If you are using OS X, and already have Homebrew installed, you should use this package manager to keep Git up to date.

When working with a package manager, you need to remember to keep your list of packages up to date. Generally this is with the subcommand update for your package manager. For example, on Ubuntu I would use apt-get update, on Fedora I would use yum check-update, and on OS X, I would use brew update.

Once the list of packages is up to date, you can install the latest packaged version of the software for your system. This is typically done with the subcommand install or upgrade.

OS X:

$ brew install git

Ubuntu, and Linux distributions using the package manager apt:

$ apt-get install git

Fedora, and Linux distributions using the package manager yum:

$ yum install git

To ensure your packages are kept up to date, you can upgrade them individually or on demand (Example B-1). This is typically done with the subcommand upgrade, although running the install command again will generally also work to upgrade the software if a newer package is available.

Upgrade with Caution.

Careful! Package managers are only mostly awesome, and sometimes upgrading everything isn’t the smartest thing when you’re running towards a deadline.

Example B-1. Update packages with Brew

OS X upgrade only Git:

$ brew upgrade git

OS X upgrade all packages installed via Homebrew:

$ brew upgrade

OS X Gotchas

When I started getting more involved in the Git community, I began working with custom builds instead of using installers so that I could test out neat new features and upgraded documentation. When I tried to push code to remote repositories, I sometimes ran into the following error:

git: 'credential-osxkeychain' is not a git command. See 'git --help'.

For some reason, my environment variable for $PATH wasn’t behaving quite the way I anticipated. After getting tired of trying to sort it out, I downloaded another copy of the keychain helper and put it in a known location on my hard drive.

It is Unlikely You’ve Lost Your Keychain.

I very, very highly doubt you will ever need to take advantage of this section. It’s mostly a love note to my future self on how I solved this problem previously. (Yes, I use my own books as reference. I write down the important stuff so that I don’t have to store it all in my own head.)

First, verify that you have the correct authentication tool set up in your global Git configuration file. This file is located at ~/.gitconfig and should contain the following settings:

[credential]
        helper = osxkeychain
        useHttpPath = true

If this is not visible in the configuration file, set it up now by running the following command:

$ git config --global credential.helper osxkeychain

Check to see if this solved the problem by running the following command:

$ git credential-osxkeychain

You should not receive the error message you had been receiving previously.

If you do receive the error message again, proceed with the following instructions. You will download and “install” a copy of the helper application osxkeychain:

$ curl -s -O http://github-media-downloads.s3.amazonaws.com/
	osx/git-credential-osxkeychain

Adjust the permissions so that you are able to run the program:

$ chmod u+x git-credential-osxkeychain

Move the helper program to the application folder for Unix-y programs. This program is run as root, so you will need to enter your OS X login password to run the command:

$ sudo mv git-credential-osxkeychain /usr/local/git/bin

Now when you run the following command, you shouldn’t get the error you received previously about a missing command:

$ git credential-osxkeychain

This documentation is adapted from the instructions at “Beginner’s Setup Guide for Git & Github on Mac OS X”. Chris Chernoff, if you ever read this, thank you! Your tips saved me from having to enter the 42-character random password I’d set up each time I wanted to push updated branches for this book to the Atlas build server while running custom builds of Git.

Accessing Git Help at the Command Line

Git includes built-in documentation from the command line. This information is accessible by running the following command:

$ git help

You can read all of the available documentation for a given topic by specifying the topic name:

$ git help topic

To navigate the help page, you can can use your keyboard’s arrow keys to scroll up and down. When you are finished reading the documentation page, press q to exit.

For a list of all topics, use the following command:

$ git help --all

A handy glossary of Git terms is also available:

$ git help glossary
..................Content has been hidden....................

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