Use git flow (avh) + npm version together

Feature -> Release

ActionBranches and their versions (before)CLI commandsBranches and their versions (after)More details
Start a featuredevelop: 1.0.0-SNAPSHOT.0
master: 1.0.0-SNAPSHOT.0

git flow feature start xxx
git flow feature publish xxx
feature/xxx: 1.0.0-SNAPSHOT.0
develop: 1.0.0-SNAPSHOT.0
master: 1.0.0-SNAPSHOT.0
Or just branch from develop
Finish a featurefeature/xxx: 1.0.0-SNAPSHOT.0
develop: 1.0.0-SNAPSHOT.0
master: 1.0.0-SNAPSHOT.0

git flow feature finish xxx
develop: 1.0.0-SNAPSHOT.0
master: 1.0.0-SNAPSHOT.0
Or just using pull requests
Start a releasedevelop: 1.0.0-SNAPSHOT.0
master: 1.0.0-SNAPSHOT.0
#create a release branch and switch to this branch
git flow release start `./next-release-version.sh`

# bump up to a release version.
# why “-no-git-tag-version” ?
## you don’t want npm to create a tag for you.
## It’s the job of git flow
npm –no-git-tag-version version patch

git commit -am “Bump up version to `./current-version.sh`”
git flow release publish
develop: 1.0.0-SNAPSHOT.0
release/1.0.0: 1.0.0
master: 1.0.0-SNAPSHOT.0

See *.sh files later
Finish a releasedevelop: 1.0.0-SNAPSHOT.0
release/1.0.0: 1.0.0
master: 1.0.0-SNAPSHOT.0
#After running it,
## changes will be merged to develop/master
### but local only.
## a tag will be be created locally, not pushed.
## Release branch will be deleted local/remote
GIT_MERGE_AUTOEDIT=no git flow release finish -m `./current-version.sh`

git checkout master
#Bump up the version to SNAPSHOT
npm version prerelease –preid=SNAPSHOT
git push


git checkout develop
# copy the bumped version from master to develop
git merge master
git push
develop: 1.0.1-SNAPSHOT.0
release/1.0.0: 1.0.0
(tag)1.0.0: 1.0.0
master: 1.0.1-SNAPSHOT.0

Source code of *.sh

The source of current-version.sh

#!/bin/sh
node -e "console.log(require('./package.json').version);"

The source of next-release-version.sh

#!/bin/sh
node -e "console.log(require('./package.json').version);" | awk -F - '{print $1}'  #Also see https://github.com/npm/rfcs/discussions/302 

Hotfix

ActionBranches and their versions (before)CLI commandsBranches and their versions (after)More details
Start a hotfixdevelop: 1.0.1-SNAPSHOT.0
master: 1.0.1-SNAPSHOT.0
git flow hotfix start `./next-release-version.sh`

# bump up to a release version.
# why “-no-git-tag-version” ?
## you don’t want npm to create a tag for you.
## It’s the job of git flow
npm –no-git-tag-version version patch

git commit -am “Bump up version to `./current-version.sh`”
git push
develop: 1.0.1-SNAPSHOT.0
hotfix/1.0.1: 1.0.1
master: 1.0.1-SNAPSHOT.0
Do code changedevelop: 1.0.1-SNAPSHOT.0
hotfix/1.0.1: 1.0.1
master: 1.0.1-SNAPSHOT.0
N/Adevelop: 1.0.1-SNAPSHOT.0
hotfix/1.0.1: 1.0.1
master: 1.0.1-SNAPSHOT.0
Do it in the hotfix branch
Finish hotfixdevelop: 1.0.1-SNAPSHOT.0
hotfix/1.0.1: 1.0.1
master: 1.0.1-SNAPSHOT.0
#After running it
## changes will be merged to master and develop( not pushed)
### You may have to resolve conflicts
## A tag will be created locally (not pushed)
## The hotfix branch will be deleted from both local and remote
GIT_MERGE_AUTOEDIT=no git flow hotfix finish -m `./current-version.sh`

git checkout master
#Bump up the version to SNAPSHOT
npm version prerelease –preid=SNAPSHOT
git push


git checkout develop
# copy the bumped version from master to develop
git merge master
git push
develop: 1.0.2-SNAPSHOT.0
hotfix/1.0.0: 1.0.0
(tag)1.0.1: 1.0.1
master: 1.0.2-SNAPSHOT.0

A quick summary of versions

  • feature and develop branch always uses a pre-release (SNAPSHOT) version, because they are not release candidates
  • release/hotfix branch always uses a release version
  • master branch always uses a pre-release(SNAPSHOT) version, because
    • it’s not a release candidate
    • merging master to develop will lead to a pre-release version on develop branch

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.