Basic workflow with Git and Drush

We are almost sure that your sites/default/files folder is ignored by the version control system. No? Do it ASAP:)

It is recommended to move your config folder to the same level (a sibling of) as your docroot directory (it fully prevents web access to it). That is not always possible and you can move it to the same level as a public files folder (sites/default/files).

Just move the folder and change the setting.php file:

$config_directories['sync'] = 'sites/default/config_HASH/sync';

After running Drush command, YAML files will be created and you can commit them. Let’s get back to admin UI.

At this stage, there are no configuration changes because we just have exported current active configuration. Let’s change something on a website (e.g. a site name) and see what happens.

We can see that one configuration item (file) was changed. Now we can see the changes:

What’s in the picture?

Stage configuration is a configuration which is saved in YAML files.

Active configuration is a current website configuration stored in a DB.

At this point, it is very important to understand differences between export and import.

Export is for taking all of the configuration defined in the DB and saving it as YAML files.

Import does the opposite action: it imports the configurations out of YAML files into the DB.

In our example, if you run import using “import all button” or running drush config-import (drush cim) command, it will wipe out a site name change to a state from YAML files (stage config).

If we want to change our staged config we have to run the export. After that, the appropriate YAML file will be changed and we can commit changes.

To summarize, a basic workflow to move changes from your dev environment to live one is the following:

On a development website:

Install the configuration management module, configure sync folder, export active configuration and commit it. Change configurations. Export changes using command: drush cex Commit and push changes: git commit and git push

On a live website:

Pull changed configs: git pull Import changes into live website active configuration: drush cim

As a result, our development and live websites get synchronized in a few simple steps.