Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

Installing and Configuring Git

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

Video Details

Duration: 10 minutes and 48 seconds
Country: United States
Language: English
License: All rights reserved
Genre: None
Views: 56
Posted by: drupalizeme on Mar 13, 2013

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.

Caption and Translate

    Sign In/Register for Dotsub to translate this video.