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:
- Create a feature branch from main
- Develop your feature locally
- Create a pull request with your feature branch to UAT
- Test preview site
- Merge pull request to UAT
- Test feature on UAT
- Create pull request with feature branch to main
- Test preview site
- Merge pull request to main
A production deployment follows these steps:
- Create pull request with main to prod branch
- Test feature(s) on preview site
- Merge pull request
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.
- From the environment branch you want to merge into (eg. uat, main), create a new branch eg. integration/my-feature
- Pull the feature branch you want to merge into your new integration branch
- Resolve any conflicts locally. In many cases this is removing composer.lock and rerunning composer install
- Commit the merges
- Push up to your integration branch and create a pull request with your integration branch.