Version control
End to end process
This article describes the end-to-end workflow, from pulling down code and creating a new branch to getting it reviewed and merged and then, finally, deploying it to production.
-
Start by pulling down the latest changes
Pull from the `main` branch
git checkout main && git pull origin main
Don’t work on the
main
branch. It’s a good practice to pull the latest changes from themain
branch before creating a new branch. -
Branch off to isolate the work in a temporary working branch
Create a new branch following the naming convention
To create a new branch and switch to it at the same time, you can run the git checkout command with the -b switch:
git checkout -b feature/search-page
Related resources
-
Work on the created branch
Commit code often when it makes sense
While working on the branch commit frequently and keep commits narrow and focused. A piece of work can contain many commits.
git commit -m "feat: add search page layout"
It’s a good idea to merge (or rebase)
main
into your branch frequently to keep it up to date avoid conflicts. -
Push to the remote repository
Push code frequently - it’s a good idea to push when you finish a piece of work.
git push --set-upstream origin feature/search-page
Once the code is published:
git push
-
Deploy the code for review
DeployAfter finishing work on a temporary branch, you can test it in Matrix, by deploying it and building
/dist
folder on the separate branch.To deploy head the the Pipeline interface in GitLab and click “New pipeline”.
- Select the branch you want to deploy (the same branch you pushed to)
- Add the variable
DEPLOY
with the valueTRUE
- Add the variable
BRANCH_NAME
with the value of the deploy branch you wish to create or update
After this pipeline runs successfully, you will see the new branch created. It will be prefixed with
deploy/
and the name of the branch you specified. This branch only contains the/dist
folder and is used to deploy the to Matrix using the Git Bridge asset. -
Test feature in the Matrix environment
DeployFind an available feature Git Bridge, one that is not in use. Otherwise create a new one. Connect it to the
deploy/
branch that was created in the previous step.Now your static assets are available in Matrix. Depending on your implementation, you may need to do some additional work to get the feature working in Matrix. You can use conditional logic to load the working code instead of the production code.
Related resources
-
Submit for review
QualityIt's now time to get the code and feature reviewed
Submit your working code for review now, both internally and externally.
Create a merge request in GitLab and move the Jira ticket into review.
Communicate with the client that the work is ready for review and provide them with the link to test the work.
Related resources
-
Respond to feedback
QualityMake the necessary changes
If there is feedback from the client or internal peer review, make the necessary changes and push them to the branch. Redeploy the code using the same branch name and Git Bridge. Keep doing this until the code passes review.
You can not proceed until your code passes client review and an internal peer review. -
Merge the working branch
Code has passed the review stage
Head the the merge request in GitLab and click “Merge”. Select “Delete source branch”.
The reviewer should have clicked the “Approve” button in the merge request. -
Deploy to production
DeployTrigger a production deploy and tag
After a successful merge of the temporary branch to the
main
, it’s time to deploy to production.Before deploying to production, chat with your team and make them aware of the deployment. There might be cases where multiple changes can go out in a single deployment. Communication is important.To deploy head the the Pipeline interface in GitLab and click “New pipeline”.
- Deploy from the
main
branch - Add the variable
DEPLOY
with the valueTRUE
- Add the variable
BRANCH_NAME
with the value ofproduction
This will update the
deploy/production
branch, that contains the/dist
directory only.More importantly, a Git tag is created using the naming convention,
production-<date>-<time>
.Created Git Tags can be found in the Repository tab under Tags.
The newly created tag will be called something like
production-20230710-064221
. Copy the tag name, ready for the next step. - Deploy from the
-
Update production Git Bridge
DeployFinally, we need to update the Git Bridge associated with the production environment. Simply paste the tag name into the Git Bridge settings and click “Update Git Bridge”.
Now your production environment is updated with the latest code. You may experience caching issues, so it’s a good idea to clear the cache in Matrix.
Using tags means you can easily rollback to previous version of your production code. -
Remove deploy branch to keep repository clean
It’s recommended to remove the deploy branch after successfully deploying a feature to production. Select the Branches tab under the Repository and locate the branch you have been working on, e.g., deploy/working-branch. Then, click on the delete option to remove the branch.
-
Production code is live
Awesome job!