Josh enforces to adopt the following described git branching strategy to keep every project on the same page when it comes to git branching.
We strongly recommend to keep following major branches in project
-
master -
origin/masterto be the main branch where the source code ofHEADalways reflects a production-ready state(production deployed code), Direct push is not allowed into this branch. -
staging -
origin/stagingto be a parallel branch tomasterbranch to stage your features for QA and user acceptance testing.(staging deployed code)Note: you can also call this branch as
uat -
develop -
origin/developto be a parallel branch ofmasterbranch where the source code ofHEADalways reflects a state with the latest delivered development changes for the next release (A working copy of code for every developer)
- Ideally feature branch should branch out from
masterbranch - if your are working on new independent and want a production deployed code for your feature. - If you don't want a production deployed code and want a code which is on
stagingordevelopthen you can branch it out from respective branch.
git checkout -b feature/MYP-1-user-sign-up where
featureis a branch namespaceMYPa three character project short code e.g. if project name ismyprojectthen code isMYP- number following project code is the feature story/task/issue number here its 1 hence
MYP-1 - project code and issue number is followed by a short feature description here its
user-sign-up
Feature branch PR should raised against develop branch only if on your dev machine following checklist is valid
-
developbranch is rebased into feature branch - Resolved all
rubocopandbreakmanissues (ruby specific tools. You use equivalant tools for other techhnologies) - All test cases are passing
- New feature is tested thoroughly
and PR is ready to merge if
- Pull request is approved
- CI build is passing
You can merge feature PR via Github UI or merge using command line.
You can merge feature branch into
-
developbranch ifstaging&developare in sync means code copy is same on both branch(Recommended approach)
git checkout develop
git merge feature/MYP-1-user-sign-up
stagingbranch ifstaging&developare not in sync and you want to give the feature branch urgently for testing.
git checkout staging
git merge feature/MYP-1-user-sign-up
Note: if feature branch is merged into staging directly DO NOT FORGOT to merge it back into develop to keep code in sync.
- if feature is merged into
developthen mergedevelopintostaging - If feature branch is merged into
staging
Then you can deploy staging branch to staging environment if
- CI build / Test cases are passing
If new feature is deployed and tested on staging successfully it's ready to deploy on production.
To deploy feature to production following steps must be followed
- Raise PR of
stagingagainstmaster - Merge PR into staging only if
- CI build/Test cases are passing
- PR is approved
- Once PR is merged its strongly recommended to create a release tag off the
masterwith release summary/notes detailing about new features being deployed. - Deploy the code to production environment
At any point after deployment you realise that there is a bug/issue on the deployed environment then to tackle this we recommend to create a hotfix branch off the targeted environment
Case 1: if bug is reported on production/master branch
- Create a hotfix branch like
hotfix/MYP-2-handle-email-uniquenessfrom master branch
git checkout master
git checkout -b hotfix/MYP-2-handle-email-uniqueness
- Fix the bug and test
- Raise PR against
master - Merge PR into
masterif
- PR is approved
- CI Build/Test cases are passing
- Deploy it to
masterby following instruction in Releasing/deploying new feature to master(production) section. - Merge
hotfix/MYP-2-handle-email-uniquenessbranch intostaging
git checkout staging
git merge hotfix/MYP-2-handle-email-uniqueness
- Merge
hotfix/MYP-2-handle-email-uniquenessbranch intodevelop
git checkout develop
git merge hotfix/MYP-2-handle-email-uniqueness
Case 2: if bug is reported on staging branch
- Create a hotfix branch like
hotfix/MYP-2-handle-email-uniquenessfromstagingbranch
git checkout staging
git checkout -b hotfix/MYP-2-handle-email-uniqueness
- Fix the bug and test
- Raise PR against
staging - Merge PR into
stagingif
- PR is approved
- CI Build/Test cases are passing
- Deploy it to
staging - Merge
hotfix/MYP-2-handle-email-uniquenessbranch intodevelop
git checkout develop
git merge hotfix/MYP-2-handle-email-uniqueness