While climbing the Drupal Ladder, Git gives you easy ways to manage changes to the code: you can apply a patch for testing, tweak the patch, experiment, re-roll it, and get back safely to where you started.
This lesson will help you install Git so that you can use it from the command line. GUI versions also exist, but for basic operations it is generally held that the command line is simpler. When you get instructions on drupal.org, while climbing the Drupal Ladder, or when asking for advice on how to use Git, the instructions will assume a command line.
Some steps are specific to your platform. The following platforms are covered in this lesson:
Installing Git on Windows and Mac
If you use Macports on Mac, you may prefer the following:
$ sudo port install git-core +bash_completion +doc +gitweb +svn
Installing Git on Linux
You can find more instructions for your particular distribution at http://git-scm.com/downloads/linux
On RPM-based systems (RHEL, Fedora Core, CentOS, ...), open Terminal and type:
$ sudo yum install git
On apt-based systems (Debian, Ubuntu, ...), open Terminal and type:
$ sudo apt-get install git-core
Moving Around on the command line
These are some commonly used commands for moving around from the command line. You should try these out and get familiar with at least these basics so you can use Git effectively from the command line.
$ cd modules
$ cd ../themes
These next commands are a simple way to update Git's configuration file, .gitconfig. The file is a hidden file that normally lives in your user home directory (e.g. on a Mac, this would be in /Users/myusername/.gitconfig). When you run these commands you won't see any response in the terminal, but your .gitconfig file will be updated.
$ git config --global user.name "Your Name"
$ git config --global user.email email@example.com
$ git config --global core.safecrlf true
Download a Project Using Git
Now you can start to use Git to download, or clone, code from Drupal.org. First we'll download a module. You will download the code directly to where you run the command from. For a module, you would typically download it into the proper place within a Drupal site, e.g. drupalroot/modules, so you would want to first cd to that directory and then proceed with a git clone command.
cd modulesfrom your Drupal root.
$ ls -a
$ git status
$ git branch -a
$ git log -3
Download Drupal Using Git
For higher rungs on the Drupal Ladder, you will want to have a Git repository for Drupal core. You can find the correct Git information for Drupal core in the same way as for projects (http://drupal.org/project/drupal/git-instructions). Doing the simple clone command below will download the cutting edge version of Drupal, sometimes referred to as HEAD, which is currently the Drupal 8 development version. Again, this code will be downloaded to the location you are in on the command line, so typically you will download this in the web root folder of your local web server.
git clone http://git.drupal.org/project/drupal.git
Once you have a Drupal 8 clone, you should always update it to the lastest code before you start new work. You can pull down all of the latest changes from Drupal.org, by moving into your Drupal 8 directory, and then doing a git pull command: