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 series 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.
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 series 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.
Joe and Blake give an introduction to the Git series giving some background on Git, and talking about the material that will be covered in the course of this series. If you aren't familiar with using the command line, you will probably want to get yourself up to speed with the basics before starting this series. We have an entire series on Command Line Basics to get you ready to go.
In this lesson we'll explain some of the basic tennents of version control systems and get some terminology out of the way by explaining things like repositories, branches, checkouts, and commits and provide you with a baseline set of concepts that we can build on through the series.
Learning Objectives:
- Understand the basic terminology of version control including repository, branch, checkout and commit.
- Understand how this vocabulary relates to Git.
- Be able to explain the difference between centralized and distributed version control systems.
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
Download Git Drupal Ladder: Install Git lesson (installs Git on Windows instead of Mac)
This lesson 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.
Learning objectives:
- Be able to use the built in git help command to find more information about specific commands
- Students should be fammiliar with documentation available online on the official Git site and on help.github.com
- Students should be familiar with the Git documentation available on drupal.org both in the handbook and on invividual project pages.
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.
Learning objectives:
- Understand the use of `git init` to initialize a new repository.
- Get the current status of your repository using `git status`.
- Use `git add` to add something to the stage and `git commit` to commit what is on our stage.
- Understand the conecpt of a stage and how Git uses the staging area.
- Understand that Git tracks content and not files so if you edit a file you'll need to add it to the stage again.
In this lesson 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.
Note that Blake is using a shortcut for his git commit
command, and is instead just using git ci
. He is also using a nice, short way to add a commit message all at the same time, by adding the -m
flag, for message, to his commit command. You can learn more about git aliases in the following video: http://drupalize.me/videos/git-aliases-and-other-fun-configuration
Blake is also using a command line modifier which displays the branch he is currently working in. There are many ways you can do this too. Blake recommends the following resource: http://www.lullabot.com/articles/git-best-practices-history-viewing-tip…
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 it's contents. We'll learn about pointers to each commit, or what Git refers to as a Treeish, and how we can use those as paramaters to different commands.
The git log alias that Blake is using to pretty-up his log is:lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset' --abbrev-commit --date=relative
.
You can find out more about adding Git aliases in Git Aliases and Other Fun Configuration (which will be published on April 10, 2013).
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 alternatly 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.
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.
This lessons 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.
In this lesson 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 some shorthand methods for creating commits more quickly. 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.
This lesson 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.
In this lesson 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.
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.
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.
Git is a Distributed Version Control system which means that the copy of the repository that you've got on your desktop is a complete clone of the repository. Make changes, commit and ... then you need to figure out how to share those changes with other people who also have a complete copy of the repository.
This lesson 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.
This lesson 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.
Git Best Practices: Upgrading the Patch Process article
Applying a patch in a feature branch
GitHub is a great, free service that lets you share your Git repositories online with others. In this lesson 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!
Set up Git (GitHub Docs)
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 acessing 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.
In this lesson 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 introducted the problem. From there it's much easier to figure out what exactly the problem is and fix it.
In this lesson, 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. If you'd like to here a good discussion of various Git workflows, and using Git with teams, you can also check out the Drupalize.me Podcast 15: Git Craziness.
Drupalize.me Podcast 15: Git Craziness
Git Series Example GitHub project