git-flow-standard-version
git-flow-standard-version copied to clipboard
Examples of using standard-version with Git flow
git-flow-standard-version
Examples of using conventional commits and standard-version with Git flow.
The Git flow branches that we are interested in are the following branches :
develop(long lived) - latest development work, deploys to a dev environmentrelease/*(short lived) - release candidate, bug fixes for a release, deploys to a test environmentmaster(long lived) - last release, deploys to a production environmenthotfix/*(short lived) - urgent fixes to production
standard-version behaviour
standard-version uses the format of your commit messages to determine the next semver version number of your release in the format major.minor.patch.
If you have only applied fix: ... commits, then it will bump your patch number, if you have applied a feat: ... commit, then it will bump your minor version, and if you have applied a BREAKING CHANGE commit, then it will bump your major number. See conventional commits for more details.
This means that if your starting version number is 1.0.0 and you apply ten fix: ... commits, then your next version number will be 1.0.1, not 1.0.10. Likewise, if you applied ten fix: ... commits and ten feat: ... commits, then your next version number will be 1.1.0.
Getting started
- Run
git flow initand configure all of the default options - When using
standard-versionfor versioning, you need to add apackage.jsonfile to the root of your Git repository - You can install yarn and use
yarn init - Add
standard-versionas a development dependency withyarn add standard-version -D - Add a
releasescript in your package.json:
"scripts": {
"release": "standard-version"
},
"standard-version": {
"skip": {
"tag": true
}
}
Note as we will be leaving release tags to
git flow, we disable them instandard-version.standard-versionwill take care of bumping ourpackage.jsonfile with the version number, and updating theCHANGELOG.mdfile with changes in each release.
Features, fixes, docs, performance improvements, refactoring, etc:
- Create a branch off of
develop - If you wish to maintain pull requests so that changes are reviewed and accepted to
develop, then you can choose not use thegit flowcommands for feature branches, and instead just push yourfeature/...orbugfix/...branches to a remote equivalent and create a pull request todevelop - Branches can actually be called anything except
develop,master,release/*, orhotfix/* - Commit messages should follow conventional commits, e.g.
feat: ...for features, andfix: ...for fixes - Other work which shouldn't affect the version number should also follow a standard commit message structure, e.g.
docs: ...orrefactor: ...
Starting a release
- Do not choose a version number yourself for your
release/*branch, instead get the next version number based from your conventional commits. - See an example script that you can add to your
package.json. - With the version number calculated for you, use the
git flow release start <version>to start a release - This will create a
release/<version>branch - Within this branch, you should then run
yarn run releaseto increment the version number withinpackage.jsonautomatically to match the release branch name, as well as updating theCHANGELOG.mdfile automatically
Bugfixing a release
- Your
release/<version>branch should deploy to a test environment - Based on testing feedback, you may need to fix a bug for that release, whilst the
developbranch has continued on into development for the next release - To do this you can create a branch off of your
release/<version>branch - If you wish to maintain pull requests for release bug fixes, then you can push your e.g.
bugfix/...branch to a remote equivalent and create a pull request intorelease/<version> - You should not run
standard-version(yarn run release) after merging a release bugfix, as you want the release version to stay the same (the release branch name and version should be immutable) - Any release bug fixes will be included in the version calculation for your next release, as well as being included in the next
CHANGELOG.md
Finishing a release
- Once happy, you can merge your
release/<version>branch intomasterand any changes back intodevelopwithgit flow release finish <version> - This also creates a tag with the version number (TODO: is this an issue with standard-version and git flow both creating a release tag?)
- The release branch is also automatically deleted
- Your production build should then begin from the updated
masterbranch and your latest release is now ready to deploy frommaster
Creating a hotfix
- If you need to fix a critical bug in production, then you need to create a hotfix
- These are branches off of
masterand can be created withgit flow hotfix start <version>- as a hotfix is a fix, you can just increment the patch version number from the last completed release, e.g. ifmasteris release 1.0.1, then create ahotfix/1.0.2branch - You must then update the
package.jsonfile to in the hotfix branch to match the hotfix branch version number (otherwise thedevelopbranch will not have its version updated when you finish the hotfix, and the tagging will fail on the next release start) - You should not run
standard-versionas you do not wish to update theCHANGELOG.md- the hotfix will be included in the next releaseCHANGELOG.md
Finishing the hotfix
- Once you have made the hotfix, you should then merge it into
masterand back into thedevelopbranch usinggit flow hotfix finish <version> - This does mean you lose the ability to do pull requests on hotfixes, and it also means you need push permission to
masterto be possible. TODO: are there ways around this? - You should not run
standard-versionwhen your hotfix is merged into master, as the fix will be included in the next release version calculation and in the nextCHANGELOG.md