Installing and Configuring Git

Video loading...

  • 0:00
    [Installing and Configuring Git]
  • 0:02
    [Introduction to Git] [Chapter 3 with Joe Shindelar]
  • 0:06
    In this lesson, we're going to take a look at getting Git
  • 0:08
    downloaded and installed, and some basic configuration options.
  • 0:12
    We'll start by going to the Git website
  • 0:14
    and downloading the package that's appropriate
  • 0:16
    for our operating system and then installing that.
  • 0:19
    After that, we're going to take a look at using the git config command
  • 0:23
    in order to configure Git and tell it things like
  • 0:26
    our name and our email address.
  • 0:28
    We'll also look at editing the .gitconfig file,
  • 0:32
    which contains that configuration information.
  • 0:35
    This allows us to do things like identify ourselves to Git
  • 0:37
    and set other basic configuration options for our local host.
  • 0:43
    Okay. So the first thing you need to do to install Git
  • 0:47
    is download the software itself.
  • 0:51
    You can do so by going to the Git website, at git-scm.com.
  • 0:56
    Once here, you can scroll down the page and click on the link for downloads.
  • 1:02
    And on the downloads page there's links for each
  • 1:04
    of the different major operating systems:
  • 1:07
    Mac OS X, Windows, Linux, and Solaris.
  • 1:11
    We're on a Mac, so we're going to download that version.
  • 1:14
    It's also got this handy little download option
  • 1:17
    in the screen over here that tries to detect the appropriate version for your hardware.
  • 1:23
    This is appropriate for me. I'm going to get the latest stable release, 1.8.1.3.
  • 1:29
    I'm going to download it for Mac.
  • 1:32
    And it goes ahead and starts downloading the file for me.
  • 1:35
    I also want to point out that on the Linux side of things,
  • 1:38
    if I were to click on this link,
  • 1:42
    it actually gives me instructions for installing Git
  • 1:44
    on a number of different Linux platforms.
  • 1:47
    So for the most part, you should be able to find your Linux platform
  • 1:50
    in the list here, and just come and run the appropriate command.
  • 1:54
    Git's open source as well, so even if you can't find
  • 1:56
    the version for your hardware, you could download the source
  • 2:00
    and compile it if you felt so inclined.
  • 2:03
    So now that we've got a copy of the file downloaded,
  • 2:06
    I'm going to close my browser window
  • 2:10
    and open up that file.
  • 2:19
    This process should be pretty much the same for Windows as well.
  • 2:23
    Download the installer; run the installer.
  • 2:26
    The actual application may be slightly different,
  • 2:32
    but the process is pretty much the same.
  • 2:36
    Yes, I'd like to open it.
  • 2:38
    I run through the installer.
  • 2:40
    I'm just going to say yes for all of these options.
  • 2:45
    And it tells me the installation was successful. Great.
  • 2:49
    I can confirm that by opening up a new terminal window.
  • 2:54
    Again, the access to the command line may be a little bit different
  • 2:58
    depending on the environment you're using,
  • 3:00
    but on a Mac I just open up the terminal.
  • 3:03
    And if I type 'which git,' in the command line,
  • 3:07
    it tells me that a copy of Git has been installed into /usr/local/git/bin/git.
  • 3:13
    I could also do something like git --version,
  • 3:18
    and that'll tell me what version of the Git software I've got installed, 1.8.1.3,
  • 3:25
    which is the latest stable release, the one we just downloaded and installed. Great.
  • 3:28
    Once I've got Git installed, there's a couple of things that I like to do right away,
  • 3:33
    some configuration tasks.
  • 3:35
    Like most software, Git has some preferences that you can set
  • 3:39
    in order to tailor how things work a little bit.
  • 3:42
    I'd like to take a look at that now.
  • 3:44
    We're going to be using the git config command in order to set up some of these variables.
  • 3:51
    We can type git config -l
  • 3:56
    to see a list of all the currently set config options.
  • 3:59
    And right now there's just one.
  • 4:02
    I want to do a couple of things, like first off, identify myself to Git
  • 4:06
    so that in the future, when I'm saving changes or committing those changes,
  • 4:11
    the application knows who to associate that change with.
  • 4:15
    I'm going to do so using the git config --global command.
  • 4:23
    So I'm setting some configuration in the global scope,
  • 4:28
    and then I'm going to set the user.name property to my name.
  • 4:35
    Like so. I'm also going to do the same for the user.email property,
  • 4:44
    though, of course, I'll change it to my email instead of my name.
  • 4:54
    Now when I view the config, list of set config parameters,
  • 5:02
    you can see that it's showing the name and email address
  • 5:05
    that I just specified. Great.
  • 5:09
    So where does Git store this information?
  • 5:12
    By default, it's storing this in a file named .gitconfig
  • 5:17
    in my user's home directory.
  • 5:22
    So when I'm in my home directory, if I do an ls -a
  • 5:25
    to show all files, including the hidden ones,
  • 5:28
    you see one there named .gitconfig.
  • 5:32
    I can open this .gitconfig file in a text editor
  • 5:35
    and go ahead and make changes to it.
  • 5:44
    So mine just has a couple lines: user in square brackets,
  • 5:48
    so the name space for this configuration key,
  • 5:52
    and then the key itself, like name or email.
  • 5:57
    Remember when we entered in our command git config,
  • 6:00
    and then we said user.name and then set it to Joe Shindelar?
  • 6:05
    The first part that preceded the dot was the name space,
  • 6:08
    and then the dot, and then the key that we'd like to set.
  • 6:12
    So then that's how we ended up with user name in this config file.
  • 6:18
    That's what a git config file looks like if you open it up.
  • 6:21
    You can edit this config file directly,
  • 6:24
    and those changes would be reflected throughout your Git global environment,
  • 6:28
    just as if you had issued the command git config and then the key
  • 6:32
    or the value that you'd like to set.
  • 6:37
    I'd also point out that when you're working with Git
  • 6:40
    you've got a global config, this .gitconfig file
  • 6:44
    that is in your user's home directory,
  • 6:47
    and that's used throughout Git,
  • 6:50
    no matter what repository you're working within.
  • 6:53
    However, you can also have a .gitconfig file per repository.
  • 6:58
    I can have configurations set up for each repository.
  • 7:02
    This is really nice for me because I have multiple email addresses.
  • 7:05
    Some of them are associated with work, like my @lullabot.com address,
  • 7:11
    and then I've also got a gmail address that's my personal account.
  • 7:14
    Depending on the project that I'm working on,
  • 7:16
    I may want to attribute those commits to my Lullabot address
  • 7:20
    for a client project, but when I'm working on a Drupal core project,
  • 7:25
    I may want to attribute those to my personal address.
  • 7:28
    So I can set my personal address in the global configuration,
  • 7:33
    and then I can set my work address on a per-project basis
  • 7:36
    in the configuration for that individual project.
  • 7:39
    There are lots of different git config options.
  • 7:45
    If we view the man page for the config command,
  • 7:50
    we can see that there are lots of different operations
  • 7:53
    that we can perform with this command, including setting
  • 7:55
    and viewing all of the different key value pairs.
  • 8:00
    And it talks about the ability to set them
  • 8:03
    for system-wide global, local, or even you can set configuration
  • 8:09
    for a specific file within a repository,
  • 8:13
    depending on the flag that you specify.
  • 8:18
    There are some options with the command for listing all of the different configurations.
  • 8:23
    You can also do something like show me all of the configuration
  • 8:26
    that's been set on a global configuration file,
  • 8:30
    show me everything that's specific to just this project.
  • 8:38
    Lots of options here.
  • 8:41
    If you scroll down to the section about files,
  • 8:44
    it explains this concept of having a global config file,
  • 8:48
    a system-wide config file that probably lives somewhere
  • 8:51
    like /etc/gitconfig.
  • 8:56
    And the order that they're listed in here is the order of precedence for these files.
  • 9:01
    So if the configuration information is in the first file,
  • 9:05
    so inside of my Git repository,
  • 9:08
    that will take precedence over the one that's in my users.gitconfig file,
  • 9:14
    which will take precedence over the local one,
  • 9:17
    which will take precedence over the system-wide one.
  • 9:22
    That's good to know.
  • 9:25
    And then there are some examples of what a good .gitconfig file might contain.
  • 9:31
    All kinds of different options that relate to the different commands
  • 9:34
    that we'll run throughout the course of this series.
  • 9:40
    So that's looking at a gitconfig file.
  • 9:43
    I'd like to have us set one more option
  • 9:45
    that I think is really common for a global config in Git.
  • 9:48
    So let's try this again: git config. I'm going to set it for the global scope.
  • 9:53
    In this case I'm going to set color.ui = true.
  • 10:01
    And I'll just run that command.
  • 10:04
    And if I do git config global -l,
  • 10:11
    there it's showing me all of the configuration that's set
  • 10:13
    in the global scope, and did indeed set color.ui equal to true.
  • 10:18
    What that will do is, throughout the course of the lessons
  • 10:21
    in which we're learning to use Git,
  • 10:23
    it will allow for some differentiation between files
  • 10:26
    in our command prompt by coloring them red and green, appropriately.
  • 10:31
    We'll see that a lot. So that's the basics of configuring Git.
  • 10:36
    There are all kinds of options available.
  • 10:38
    I encourage you to check out the documentation
  • 10:40
    on the Git website for various configuration flags.
  • 10:45
    We'll also talk about a few more of these throughout the course of this series.

Installing and Configuring Git

Loading...

In this lesson we take a look at the methods available to install Git on different operating systems including Windows, OS X, and Linux and how to ensure that you're environment is properly setup to start using Git. Then we walk through the installation on OS X and finally we'll cover how to invoke Git from the command line and set some basic configuration options like telling Git who we are. If you would like to see Git installed on Windows, you can take a look at our Drupal Ladder: Install Git lesson. Learning objectives:

  • Know where to go to download the latest verion of Git
  • Be able to install Git on your operating system of choice.
  • Be able to verify that Git is indeed running in your environment.
  • Do some Git configuration with `git config`, ~/.gitconfig
Resources: 

Download Git Drupal Ladder: Install Git lesson (installs Git on Windows instead of Mac)

Average review

0
No votes yet

Reviews