Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git and Drush: Best Friends Forever

Git and Drush: Best Friends Forever

A short introduction to git (the distributed version control system) and drush (the command-line interface for Drupal) and how they can play nicely together.

This presentation was delivered to the Drupal Western Australia User Group in May, 2012.

Thomas Sutton

May 01, 2012
Tweet

More Decks by Thomas Sutton

Other Decks in Programming

Transcript

  1. A bit about git • Free & open source software.

    • Distributed version control system.
  2. A bit about git • Free & open source software.

    • Distributed version control system. • Every clone is a full-fledged repository.
  3. A bit about git • Free & open source software.

    • Distributed version control system. • Every clone is a full-fledged repository. • Branches and tags are first class and working with them is easy.
  4. A bit about git • Free & open source software.

    • Distributed version control system. • Every clone is a full-fledged repository. • Branches and tags are first class and working with them is easy. • The Drupal community standard.
  5. Use git to: • Track the development history of a

    project. • Tag builds, releases, etc.
  6. Use git to: • Track the development history of a

    project. • Tag builds, releases, etc. • Share and transfer code between people, organisations, etc.
  7. Use git to: • Track the development history of a

    project. • Tag builds, releases, etc. • Share and transfer code between people, organisations, etc. • Deploy code.
  8. Platform releases • Store platforms in a git repository. •

    (Restricted write access.) • Use this repository as a remote in project repositories.
  9. Platform releases • Store platforms in a git repository. •

    (Restricted write access.) • Use this repository as a remote in project repositories. • Now code upgrades are just merge, cherry- pick, rebase, etc.
  10. Platform releases • Starting a new project is just a

    clone:
 git clone \
 --origin platform \
 --branch 6.x \
 git@gorilla:drupal.git \
 example.com
 git checkout -b master
  11. Platform releases • Or, manually:
 git init
 git remote add

    platform ...
 git fetch platform
 git checkout \
 -b master \
 remotes/platform/7.x
  12. Platform releases • After it’s created, you just do your

    normal thing:
 git remote add origin ...
 git add .
 git commit -m “Make it awesome”
 git push origin master
  13. Platform releases • When it’s time to upgrade a project

    to a new platform release:
 git fetch platform
 git merge remotes/platform/7.x
  14. Platform releases • When it’s time to upgrade a project

    to a new platform release:
 git fetch platform
 git merge remotes/platform/7.x • Or use rebase:
 git fetch platform
 git rebase remotes/platform/7.x
  15. A bit about drush • A command-line interface for Drupal.

    • Built-in commands for core Drupal functionality.
  16. A bit about drush • A command-line interface for Drupal.

    • Built-in commands for core Drupal functionality. • Extension system for other modules to provide commands (Features, Migrate, etc.)
  17. A bit about drush • A command-line interface for Drupal.

    • Built-in commands for core Drupal functionality. • Extension system for other modules to provide commands (Features, Migrate, etc.) • Underpins systems like Aegir.
  18. Use drush to: • Download, enable, disable and upgrade themes

    and modules. • Build and install complete sites.
  19. Use drush to: • Download, enable, disable and upgrade themes

    and modules. • Build and install complete sites. • Manage users and roles.
  20. Use drush to: • Download, enable, disable and upgrade themes

    and modules. • Build and install complete sites. • Manage users and roles. • Operate on your database.
  21. Use drush to: • Download, enable, disable and upgrade themes

    and modules. • Build and install complete sites. • Manage users and roles. • Operate on your database. • Transfer databases and files.
  22. Scripts • Here’s an example script:
 <?php node_delete(1); • When

    you save it as example.php (in a specific directory).
  23. Scripts • Here’s an example script:
 <?php node_delete(1); • When

    you save it as example.php (in a specific directory). • You run it like this:
 drush php-script example
  24. Scripts • Here’s an example script:
 <?php node_delete(1); • When

    you save it as example.php (in a specific directory). • You run it like this:
 drush php-script example • Easy!
  25. Database diff • Lets go back to the sql-dump command.

    • It has a few options: • skip-tables-key - leave tables out.
  26. Database diff • Lets go back to the sql-dump command.

    • It has a few options: • skip-tables-key - leave tables out. • structure-tables-key - leave the data out.
  27. Database diff • Lets go back to the sql-dump command.

    • It has a few options: • skip-tables-key - leave tables out. • structure-tables-key - leave the data out. • ordered-dump - make the dump line- based.
  28. Database diff 2 • Lets go back to the sql-dump

    command. • It has a few options:
  29. Database diff 2 • Lets go back to the sql-dump

    command. • It has a few options: • skip-tables-key - leave tables out.
  30. Database diff 2 • Lets go back to the sql-dump

    command. • It has a few options: • skip-tables-key - leave tables out. • structure-tables-key - leave the data out.
  31. Database diff 2 • Lets go back to the sql-dump

    command. • It has a few options: • skip-tables-key - leave tables out. • structure-tables-key - leave the data out. • ordered-dump - make the dump line- based.
  32. Database diff 3 • The “key” options reference values in

    your drushrc.php configuration file.
  33. Database diff 3 • The “key” options reference values in

    your drushrc.php configuration file. • Your drushrc.php can also contain defaults values for all drush command arguments.
  34. Database diff 3 • The “key” options reference values in

    your drushrc.php configuration file. • Your drushrc.php can also contain defaults values for all drush command arguments. • Setting defaults for these makes sql- dump much more useful!
  35. Git and Drush • Both are extremely flexible. • Both

    are easy to extended. • Both are great fun. • Bend them to your will! • (But please read the documentation first.)