C H A P T E R  2

images

Essential Tools: Drush and Git

by DaniNordin and Benjamin Melançon

“There is no knowledge that is not power.”

—Ralph Waldo Emerson

Whether building sites, developing themes or modules, or trying to make a Drupal distribution that can drive your car, Drush (the Drupal shell) and Git (the open source version control system) will help you get where you are going quickly and safely. This chapter will give you a brief overview of Drush and Git and then it will help you get started with these powerful tools. If you are already familiar with Drush, or want to go deeper into all of the things that you can do with it, check out Chapter 26, “Drush.”

Drush is easy to explain. It lets you perform all manner of repetitive Drupal tasks much, much faster. Need to upgrade your code? Use drush up. Need to download a new module? Use drush dl MODULE_NAME. Drush does the rest of the work—usually within a minute or two (see Figure 2-1).

Git may be a little harder to explain. The short explanation is that if you are not using version control, you need to. If you are the pesky type of person that expects reasons for doing things, here's a slightly longer explanation: have you ever wanted an undo or rewind button for life? That's version control. The best way to perform backups of your work is with a properly configured version control system (VCS), which you use constantly to record changes to a file or set of files over time so that you can revert to or compare specific versions later.

Like most developers, we made our first sites without version control. And like most developers, we have a tale or two of minor catastrophes, from the change that broke a site in Internet Explorer to the deleting of three days' work. But you get the benefit of our experience, and we're going to make you start off doing it right. Before we get into that, however, we need to set up some foundations. You need to install Drush and Git.

images Tip You can also use Git to track changes for non-Drupal projects, even folders with only one file in them.

images

Figure 2-1. Upgrading Drupal with the drush up command. Total time? About 30 seconds. Manually? 15 minutes to a couple of hours, depending on how many modules need to be upgraded.

A Beginner's Guide to Installing Drush

Installing and using Drush—a command line tool that lets you do things on your Drupal site like update modules via two word commands—is a no-brainer. But even hard-core Drupal users have been late to experience the benefits of Drush because they put off the little bit of up-front work that would make their lives easier. For people new to Drupal, or those of us raised with a love of pixels and a distaste for the command line, the idea of installing Drush can be overwhelming.

This section provides a simple guide to installing Drush.

THINGS TO KNOW BEFORE YOU GET STARTED

This will create a backup of your database file in the location of your choosing. One thing that Drush doesn't do automatically, however, is empty the cache tables; this can cause the database backups to be overly large, which will fill up your repository quickly. The Drupal Git Backup script addresses this, and Chapter 26 explains how to exclude selected tables from export. Another approach is to simply clear your cache using the command drush cc all before making a database backup. This command will clear all of the database cache tables.

Summary

We hope that this chapter has given you a quick overview of how important (and how easy!) it is to keep your code in version control and your database backed up during development. By setting up a few key processes up front, you can save yourself hours of headaches down the line; ask anyone who has ever taken their programming down the wrong path or dealt with a crashed site. You'll thank us later.

images Note Get the essential updates to the tools and tips we missed as people correct us at dgd7.org/essential.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.112.160