Keep Drush Up to Date

Alan Ivey's picture

We're big fans of Drush. It's installed on all of our servers and it's a great way to perform maintenance tasks, download core and modules, and much much more. I'm not a big fan of installing from zip files though, so let's use git to easily keep our Drush install up to date.

Before the git transition, I would use Subversion to check out the latest drush release somewhere, like /usr/local/drush (on my Mac), using the CVS clone Subversible. Today, however, I noticed that the latest tagged release Subversible has is 4.2, and the Drush project page has 4.4 ready to download. I figured now would be a good time to start using git for this and stop relying on a third-party to provide the code for Subversion.

The commands below will walk through cloning the Drush git repository and then switching to the latest release. I realize the drush self-update will soon make this irrelevant, but this method works today and is a great exercise in learning how Drupal is using git, especially important coming from Subversion.

Clone the repository. It will create the subfolder "drush" from your current working directory: $ git clone --branch master http://git.drupal.org/project/drush.git
$ cd drush
Use pear to download includes/table.inc. This one-liner will take care of everything for you as long as you have pear installed and are in the new drush directory: $ pear download Console_Table && tar zxvf `ls Console_Table-*.tgz` `ls Console_Table-*.tgz | sed -e 's/\.[a-z]\{3\}$//'`/Table.php && mv `ls Console_Table-*.tgz | sed -e 's/\.[a-z]\{3\}$//'`/Table.php includes/table.inc && chmod 0644 includes/table.inc && rm -fr Console_Table-* At this point you may or may not have a functioning Drush installation, because you're using the HEAD of the Drush code repository and it might contain broken code. I would recommend switching the checkout to the latest release. We'll start by viewing all releases: $ git tag
5.x-1.0
5.x-1.0-beta1
5.x-1.0-beta2
... snip ...
7.x-4.2
7.x-4.3
7.x-4.4
debian/4.3-1
debian/4.4-1
As of this writing, there are over 50 results from this command, but you'll see the latest is "7.x-4.4". If we want our local Drush install to be at 4.4, change the checkout: $ git checkout 7.x-4.4
Previous HEAD position was 1532d0c... #1079434 by msonnabaum. Add .gitignore for includes/table.inc
HEAD is now at a808ff0... Updating drush version
That's it! Drush is set up on 4.4: $ drush --version
drush version 4.4
Let's say 4.5 is released tomorrow and you want to change your checkout. First you'll need to update the local git repository: $ git pull View the list of tags: $ git tag
5.x-1.0
5.x-1.0-beta1
5.x-1.0-beta2
... snip ...
7.x-4.3
7.x-4.4
7.x-4.5
debian/4.3-1
debian/4.4-1
debian/4.5-1
And switch your checkout to the new release: $ git checkout 7.x-4.5

Repeat for future releases, and enjoy! Of course, once drush self-update begins working, that will be the preferred method, but this will work today. Please questions or comments below.

Comments

sdboyer's picture

Nice intro for folks. Two quick things:

$ git clone --branch master http://git.drupal.org/project/drush.git

This is the command provided by the Git instructions, yep, but it's actually redundant. master is the default branch for all Drupal.org git repositories right now, so specifying it explicitly doesn't do anything extra. We'll be adding features soon enough that let repository owners specify a different default branch, at which time we'll probably also update the Git instructions so that they reflect this.

At this point you may or may not have a functioning Drush installation, because you're using the HEAD of the Drush code repository

HEAD has a different meaning in Git; it refers to whatever is currently checked out in your local repository - which can be any branch, not some canonical branch. Better to say "branch tip" or "dev version" or some such.

Alan Ivey's picture
Member since:
19 May 2008
Last activity:
8 hours 26 min

Thanks for the tips. I'm coming from Subversion so I need to learn the new terminology.

dalin's picture

My git checkout as of 2hrs ago has includes/table.inc

Alan Ivey's picture
Member since:
19 May 2008
Last activity:
8 hours 26 min

Interesting. 4.5-dev has a .gitignore file in the includes folder with "table.inc" so ignore it. I'll look into this further, and in the meantime I'll edit this post to only download if the file doesn't exist.