Skip to content

Contribute your code: working with Git

The general idea is to do all your work locally in a feature branch, review the changes in the Preview environment, and then merge back into the appropriate environment branch. Don't be afraid to create lots of small branches. Every discrete feature that you build should begin life inside its own dedicated feature branch.

The Git workflow in WebOps requires the use of Composer, a PHP dependency manager, to manage Drupal core and it’s associated contrib modules. If you are unfamiliar with Composer, please refer to Composer's documentation

To create a feature branch, commit and test your code, follow these steps:

  1. Create a feature branch from main
  2. Develop your feature locally
  3. Create a pull request with your feature branch to UAT
  4. Test preview site
  5. Merge pull request to UAT
  6. Test feature on UAT
  7. Create pull request with feature branch to main
  8. Test preview site
  9. Merge pull request to main

A production deployment follows these steps:

  1. Create pull request with main to prod branch
  2. Test feature(s) on preview site
  3. Merge pull request
image from kim, but will need some tweaks for WebOps

Command line workflow for creating and submitting a feature branch in WebOps

Make sure the main branch is up to date

 > git checkout main
 > git pull origin main

Get any new updates or changes to composer.json

 > composer install

Import config into Drupal

 > ./vendor/drush/drush/drush csim -y

Create a new feature branch

 > git checkout -b feature/MYBRANCH-123

Develop new code or features

Export config for default and active split from Drupal

 > ./vendor/drush/drush/drush csex -y

Update composer.lock if any changes to composer were made

 > rm composer.lock
 > composer install

Add the composer files to be staged

 > git add composer.*

Add any configuration files (individually) for changes

 > git add web/sites/config/sync/< my-config-file >.yml

Commit your files to your local git

 > git commit -m "my message, updating composer.json and composer.lock"

Push up your changes to your feature branch and create a pull request in the WebOps.

 > git push origin feature/MYBRANCH-123

Integration branches

Sometimes you may run into a conflict or may not be able to merge a branch cleanly. In this case you need to create an integration branch.

  1. From the environment branch you want to merge into (eg. uat, main), create a new branch eg. integration/my-feature
  2. Pull the feature branch you want to merge into your new integration branch
  3. Resolve any conflicts locally. In many cases this is removing composer.lock and rerunning composer install
  4. Commit the merges
  5. Push up to your integration branch and create a pull request with your integration branch.
image from kim, but will need some tweaks for WebOps