Guide
Deploy Drupal Site Configuration Using Drush and Git
Learn how to export Drupal configuration to YAML, version it with Git, and import it on another environment using Drush, with verification and rollback steps.
Published by Tasadduq Burney
09 Jan 2026, 06:10 UTC
3 min69.1K views0

Desired outcome
Export Drupal site configuration to YAML, store it in Git, and import it on another environment so that content types, fields, views, roles and site settings are identical across dev, staging and production.
Prerequisites
- Drupal core 9.5 or later (or Drupal 10) with Drush 12+ installed.
- Access to the command line on each environment with permissions to run drush and write to the config/sync directory.
- A Git repository initialized and accessible from each environment.
- The site UUID must be known or set to the same value on all environments.
Procedure
- Prepare the development environment
- Log in to the dev site admin UI and make the configuration change (e.g., add a field to an article content type).
- Run
drush config:export(aliascex) to write all active configuration toconfig/sync. - Verify the export:
ls config/sync/*.ymlshould show updated files.
- Commit configuration to Git
- From the repository root, add the changed YAML files:
git add config/sync. - Commit with a descriptive message:
git commit -m "Add field subtitle to article content type". - Push to the remote:
git push origin main.
- From the repository root, add the changed YAML files:
- Deploy code and configuration to target environment
- On the target (staging or production) server, pull the latest code and config:
git pull origin main. - Clear Drupal caches to ensure the system reads the latest YAML:
drush cr. - Run database updates if any code changes require them:
drush updatedb -y. - Import the configuration:
drush config:import(aliascim).
- On the target (staging or production) server, pull the latest code and config:
- Verify the import
- Check for differences:
drush config:statusshould report "No differences". - Spot‑check a known change in the admin UI (e.g., the new field appears on the article edit form).
- Review the recent watchdog log for import errors:
drush watchdog:show --type="php" --limit=10oradmin/reports/dblog.
- Check for differences:
Recovery options
If the import fails or produces an unwanted state:
- Roll back the Git commit that introduced the bad YAML:
git revert <commit‑hash>. - Pull the reverted state on the target environment and run
drush config:importagain. - As a safety net, keep a database dump taken before the import; restoring the dump returns the site to its pre‑import configuration.
Limitations and practical checks
- Configuration import does not delete content; removing a content type that still has nodes will fail or leave orphaned data. Verify that no content depends on the removed element before importing.
- Environment‑specific values (API keys, SMTP credentials) should be kept out of
config/syncusing the Config Split or Config Ignore contributed modules, or overridden insettings.phpvia$config['system.site']['name'] = 'Staging Site';. - Drush command names and flags can differ between Drush 9 and Drush 12; consult
drush --versionand the relevant documentation for your installed version.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.