Moving to git hasn’t been easy. We, at DeltaX, moved from SVN source control over 6 months ago now. I write this to give an overview/early reaction on how it has been working for us.
We had an SVN repository, until Nov 2017, that included most of the projects for and around the web application. Essentially this mono-repo was being used by all developers around the table. The different three deploy environments were each branches on the same repo, along with one development (“trunk”) repository. This repository has been in use for the last 5 years of DeltaX, forked just a year before this migration. The fork covered nearly 30 thousand commits, performed by an average of 20 developers.
Prerequisites for new flow
- Inspired by distributed version control systems (DVCS) implementations like git-flow. Alas! It wouldn’t work because of the next requisite.
- Need to have keep a similar environment workflow. That is, to have three environments,
- Ability to take features from one branch to another without much hassle.
- Three Permanent Branches
- master (deploys to Production)
- staging (deploys to Staging)
- develop (deploys to Testing)
- Multiple feature and hotfix branches which are in active development.
- feature/dx-AAAAA-My-One-Line-Description (like dx-1234-rich-media-creatives)
- hotfix/dx-AAAAA-My-One-Line-Description (like dx-4321-rich-media-creatives-upload-fails)
- All development happens on feature and hotfix branches
- Feature Workflow
- Feature branches are remote branches too
- Make sure feature branch is a checkout of development
git checkout -b feature/DX-
is an feature/issue card, that we track on Atlassian Jira.
- Commits are pushed to remote feature branches periodically. Convention to commits can be found [here].
git commit # DO NOT USE "git commit -m" !! We want well described commits.
- Every commit shall include the Jira card numbers that it relates to. This helps us to look it up easier on the CLI or even on Bitbucket.
- When a feature is “Dev Complete,” then merge develop to ensure there’s nothing breaking, then, a pull request (PR) is created to merge the feature into the develop branch. The PR is reviewed by at least one person (usually the whole team is added to the review) for approval.
git checkout develop git pull origin develop git checkout feature/DX-... git merge develop # Ensure nothing breaks
- Peer review changes (if any) are implemented under the same PR.
- On merge to develop branch, the feature is deployed to testing environment.
- The feature is tested on the testing environment.
- On testing completion, a release branch is merged to staging, which is then QA tested. A merge here should not arise to any conflicts, if it does your master may be dirty too, with probably a relating hotfix.
git checkout staging git pull origin git checkout -b release/DX-1234-My-Feature-Branch git cherry-pick $(git rev-list --reverse --no-merges --grep "DX-<card-number>" staging..develop)
- Deployment scenarios
- You may keep your feature on staging to be deployed at the end of the sprint, or
- You can further merge the release branch to master to make it production deploy ready.
- At the end of the fortnightly sprint the staging branch as-is is merged to master. Tagged appropriately with release number.
- Hotfix Workflow
- Hotfix branches are remote branches too.
- Make sure hotfix branches are checked out from master as they have to end in production without any new code.
git checkout master git checkout -b hotfix/DX-...
- Hotfixes may merge into any of the first two permanent branches (i.e. master & staging)
- Ideally, hotfixes should be tested on staging and then (the hotfix branch) merged later to master for production deployment.
- Do remember to merge the hotfix branch to develop.
Differences from SVN
- No need to checkout develop before commiting.
Every code commit on SVN required the developer to be connected to the internet in order to apply the changes on the server. This not only increased development time and productivity but also the commit history is not relatable at all. Every commit was made directly on the environment branch.
- Better code-reviews.
The code-reviews have become much easier than it was previously performed, even more productive with the web interface of the pull request mechanism. One secret sauce is to have ensure all commits include the Jira issue identity so that we can find the progress of a card on Jira too and other related advantages.
- Blames and online code exploration is much easier.
Using the web interface to blame and understand which changes have been pushed to a specific branch eases resolution of many conflicts and root cause analysis of issues.
In the last 6 months, the 25 developers have commited over 5 thousand commits and played around with this repository of millions of lines of code. The shift has given way to a smoother deploy process and much better development experience. While there are companies, like Facebook, who are moulding mercurial, a DVCS, to be inclined towards centralised versioning system, we are venturing into the realm of distributed. Moreover, this progress gives us a chance to rethink the monorepo architecture itself, to learn from the mistakes of others.