Introduction to Git

Git is a distributed version control system (DVCS) for source code management (SCM). It's like a giant undo button for everything you've ever done on a project throughout its entire existence. Git also provides some powerful tools for collaborating with your team, browsing a project's entire history, deploying code, and so much more. Git is the version control system used for Drupal core and contributed module development and, as such, is used by most people building sites with Drupal to keep track of their client work as well. It's also the system used to track development of the Linux kernel, Ruby on Rails, Android, and many, many other projects. This is an in-depth course that starts with the basics of version control, establishes some terminology, and a base line workflow, then continues to build on that by going beyond the basics of the various Git commands to make the most out of your tools.

Tutorials in this course
More information

This is an in-depth course that starts with the basics of version control, establishes some terminology, and a base line workflow, then continues to build on that by going beyond the basics of the various Git commands to make the most out of your tools.

More information

In this tutorial we'll explain some of the basic tenets of version control systems. We'll define Git terminology like repositories, branches, checkouts, and commits, and provide you with a baseline set of concepts that we can build on throughout the course.

More information

In this lesson we take a look at the methods available to install Git on different operating systems including Windows, Mac OS, and Linux and how to ensure that you're environment is properly setup to start using Git. Then we walk through the installation on Mac OS 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.

  • 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

Additional resources

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

More information

This tutorial takes a look at the various resources that are available for getting help with Git including the built-in manual/help pages and examples as well as other documentation that we've found to be useful while learning how to use Git.

More information

In this lesson we're going to quickly jump into the basics of a whole bunch of different git commands and get our repository created, add a couple files, and then view our log.

More information

In this tutorial we'll take a look at creating branches with the git branch command, and tags with the git tag command and explain the differences. Then we'll look at how and when they can be used and how to move changes from one branch to another using the git merge and git rebase commands and talk about the different ways in which those two commands effect the history of a project.

More information

There are a lot of different ways to reference a specific commit in Git. This lesson takes a look at the various ways in which you can navigate through the history of a project by cloning the Drupal core repository from Drupal.org and looking at its contents. We'll learn about pointers to each commit, or what Git refers to as a Treeish, and how we can use those as parameters to different commands.

More information

This lesson covers the git diff command and how to use the command along with a Git Treeish reference to view the differences in a project or a single file between two commits. Or between the current HEAD and the working tree. We'll also take a look at integrating Git with some external diff tools that make reading the output from the git diff command a bit easier.

More information

In the real world when you're working on a project with a team of people your code never stands still. It's not at all uncommon to find yourself in a scenario where git merge or git rebase simply can't successfully meld two branches without human interaction. For example when both branches contain a commit that modifies the same line of code in a file in different ways. This lesson will take a look at how you can go about resolving these merge conflicts and some of the tools available to help make this process easier by first creating an intentional conflict between two branches and then showing how to resolve it.

More information

This tutorial dives deeper into the different things you can do with the git add command. Things like adding multiple files at a time using wildcards and staging and adding only some of the changes you've made in a file and not all of them. We'll also take a look at using a .gitignore file to exclude specific files or even patterns of files from the repository all together.

More information

In this tutorial, we revisit the git commit command and take a look at some of the additional things you can do with it, like amending a previous commit, and creating commits using shorthand methods. Then we'll look at using the interactive rebase command which will allow us to reword commit message and do other things like squash two commits into a single commit when performing a rebase.

More information

This tutorial takes a look at removing files from your version control system. It's generally not enough to just delete the file in the file system you also need to tell Git that it's been removed and make a commit with that information.

More information

In this tutorial, we'll take a look at ways that you can remove changes that you've made to the files in your working tree, how to remove something from the index that you've added but later decided that you're not ready to commit, and some other basic working tree and index house cleaning commands.

More information

It happens to the best of us, sometimes we commit something that just simply wasn't ready, or maybe we're having a bad day and introduced a bug to the code. I've even seen scenarios where you've created a temporary workaround in your codebase and now you're ready to remove that workaround and put in a real fix. This lesson looks at using the git revert command to deal with these scenarios by creating new commits that reverse the changes of a previous commit.

More information

This lesson is all about making two git repositories talk to one another. So far everything we've done has been on your desktop. But we're going to need a way to share changes with other people on our team, or deploy them to our production site. To do that we're going to learn about the git clone, push, pull and fetch commands.

More information

This tutorial takes a look at using the git stash commands to temporarily preserve your work when you need to incorporate other changes but aren't quite ready to fully commit them.

More information

This tutorial takes a look at applying a patch from Drupal.org to your local copy of a module or Drupal core using Git. Afterwards we'll look at how you can create your own patches, using git diff and git format-patch, in order to contribute code back to Drupal or any of the module's on Drupal.org. You can see a full Git workflow using GitHub in the lesson Git Workflow: Putting It All Together.

Additional resources

Git Best Practices: Upgrading the Patch Process article
Applying a patch in a feature branch

More information

GitHub is a great, free service that lets you share your Git repositories online with others. In this tutorial, Blake gives a quick tour of our Git Series Example GitHub project, and then explains how pull requests work, letting you merge changes into the repository through the UI. Feel free to try it out by adding jokes to our new jokes.txt file!

More information

We've now learned about all sorts of commands in git and the flags that accompany those commands. We've also seen that some of those commands can get to be a bit long and are used quite often. In this lesson we're going to take a look at how to create command aliases in our .gitconfig file so that we can have a shorthand for accessing some of these more esoteric commands. We'll also take a quick tour of Joe's personal .gitconfig file that he uses in his day-to-day work.

More information

In this tutorial we're going to use the git bisect command to do a little bit of debugging. We're all human, and sometimes bugs get introduced our software and we may not notice them for a while. Especially on fast moving projects. A good example of this would be a performance regression, and now you want to figure out what commit made everything run slower all of a sudden. Bisect allows us to do a binary search between a known good commit and a known bad commit and quickly narrow down which commit introduced the problem. From there it's much easier to figure out what exactly the problem is and fix it.

More information

In this tutorial, Joe walks you through a typical Git workflow. We start with cloning a repository, creating a branch, and getting some work done. Then we go ahead and commit our work, merge it into the master branch, and push our changes back up to the remote repository.

Topics