Easy Drupal 8 configuration management with fellow developers

Credit : Pantheon

I’ve met developers that are using Drupal 8 but not using Configuration Management as they’re not familiar with it (or even scared it’s too complicated). Instead they move databases around, constantly exporting, importing and sending to eachother. This takes a lot of time, is error prone unless you take lots of care to and means developers are waiting for eachother to finish before they can start working with configuration.

Why this is important in a wider context

This is especially important when reaching a stage in a development project when clients have already started content entry in the ‘Live’ environment. At this point it is imperative to commit config as code so it can go from Local>Dev>Test>Live for it to apply and combine nicely with their content changes in the database. This means not having to worry about overwriting their content changes with development configuration changes, this definitely won’t make content editors happy!

Tip : Don’t work directly on Dev

Don’t work directly on the dev branch, instead have a separate branch per developer or create a new feature branch on each task or group of tasks. This will help to reduce conflicts.

Exporting from Local to Dev

  1. Export current config of remote Dev site (drush cex), commit the changes and push them to the repository.
  2. ‘Git pull’
  3. Import config on local with ‘drush cim’
  4. Create a new feature branch, then start your work
  5. Makes changes in your local database. When ready to export configuration, run ‘drush cex’
  6. Commit changes with git, starting commit message with “[config] ..” (you don’t have to, this is just how I like it)
  7. ‘Git push’

Merging your feature branch with Dev master branch

Once ready, we need to merge our individual dev branch with Dev so that other developers will get your changes. It is recommended that this is done as frequently as possible to avoid any large merge conflicts, small ones are easier to compare and fix.

  1. Commit any changes that have been made on Dev with ‘Drush @site.dev cex’. Push that to origin from the Dev site
  2. ‘Git checkout dev’ (master dev branch)
  3. ‘Git pull’
  4. ‘Git merge feature-branch’
  5. ‘Git push’

Importing from Dev to Local

It’s important to push any local uncommitted configuration changes you have to git first to prevent them being overwritten when importing colleagues changes

  1. ‘Git pull’
  2. ‘Drush cim’ (imports configuration)

Importing to Dev environments

Doing this using the UI is safer than running the drush command

  1. Open the ‘Configuration Synchronisation’ page available at /admin/config/development/configuration
  2. Review differences
  3. If happy proceed by clicking the ‘Import all’ button