Pre-release Branches & Channels
A single main branch is enough until you want to publish a beta of the next major version while still shipping fixes for the current one, or keep patching 1.x after 2.0 is out. semantic-release models both with its branches setting, and it maps each branch to a distribution channel (an npm dist-tag, a GitHub pre-release).
Branch types
| Type | Config | Versions it may release | Channel |
|---|---|---|---|
| release | "main", "next" |
regular versions; a later release branch takes higher versions | main → default channel (latest), others → their name |
| pre-release | { "name": "beta", "prerelease": true } |
X.Y.Z-beta.N |
beta |
| maintenance | "+([0-9])?(.{+([0-9]),x}).x" (matches 1.x, 1.5.x) |
only within its range (1.x → >=1.0.0 <2.0.0, and below the release branches' versions) |
the branch name |
The pre-release identifier defaults to the branch name; "prerelease": "rc" uses another one. Pre-release counters start at 1 (2.0.0-beta.1), unlike npm's .0.
A session: beta, stable, maintenance
One repository, one config, six pushes. After each push the session runs semantic-release (non-dry, against the bare remote) and prints only the decision lines:
git init -q --bare remote.git
git clone -q remote.git app 2>/dev/null && cd app
cat > .releaserc.json <<'JSON'
{
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"main",
{ "name": "beta", "prerelease": true }
],
"repositoryUrl": "file:///home/learner/remote.git",
"plugins": [
["@semantic-release/commit-analyzer", { "preset": "conventionalcommits" }],
["@semantic-release/release-notes-generator",
{ "preset": "conventionalcommits", "linkCompare": false, "linkReferences": false }]
]
}
JSON
release() {
echo "[$(git branch --show-current)] $1"
semantic-release --no-ci 2>&1 | sed -E 's/^\[[^]]+\] \[semantic-release\] › . +//' \
| grep -E '^(The next|There is no previous|Published|Add channel|There are no)' | sed 's/^/ /'
}
git add -A && git commit -q -m "feat: initial app" && git push -q origin main
release "first release"
git switch -q -c beta
git commit -q --allow-empty -m "feat(api)!: new session API" -m "BREAKING CHANGE: Client was renamed to Session."
git push -q origin beta
release "breaking change on beta"
git commit -q --allow-empty -m "fix(api): session timeout"
git push -q origin beta
release "fix on beta"
git switch -q main
git commit -q --allow-empty -m "fix: typo in --help"
git push -q origin main
release "fix on main while the beta runs"
git merge -q --no-edit beta && git push -q origin main
release "beta merged into main"
git branch 1.x v1.0.1 && git switch -q 1.x
git commit -q --allow-empty -m "fix: security fix for 1.x users"
git push -q origin 1.x
release "fix on the maintenance branch"
echo "--- tags"
git tag --sort=v:refname | tr '\n' ' '; echo[main] first release
There is no previous release, the next release version is 1.0.0
Published release 1.0.0 on default channel
[beta] breaking change on beta
The next release version is 2.0.0-beta.1
Published release 2.0.0-beta.1 on beta channel
[beta] fix on beta
The next release version is 2.0.0-beta.2
Published release 2.0.0-beta.2 on beta channel
[main] fix on main while the beta runs
The next release version is 1.0.1
Published release 1.0.1 on default channel
[main] beta merged into main
The next release version is 2.0.0
Published release 2.0.0 on default channel
[1.x] fix on the maintenance branch
Add channel 1.x to tag v1.0.1
The next release version is 1.0.2
Published release 1.0.2 on 1.x channel
--- tags
v1.0.0 v1.0.1 v1.0.2 v2.0.0 v2.0.0-beta.1 v2.0.0-beta.2
Follow the versions:
- The breaking change on
betaproduced2.0.0-beta.1, and the next fix2.0.0-beta.2: on a pre-release branch, later commits bump the counter, not the version. - Meanwhile
mainreleased1.0.1on the default channel. Users onlatestnever saw the beta. - Merging
betaintomainreleased 2.0.0: the same commits, now as a final release. - The
1.xbranch was created fromv1.0.1. semantic-release first noted thatv1.0.1belongs to the new1.xchannel ("Add channel 1.x to tag v1.0.1"), then released the security fix as 1.0.2 on that channel. - Had the 1.x branch contained a
feat!:commit, the release would have failed withEINVALIDNEXTVERSION: "The release2.0.0on branch1.xcannot be published as it is out of range", and only versions in>=1.0.2 <2.0.0-beta.1would be allowed there. That guard is the main reason to declare maintenance branches instead of releasing from arbitrary branches.
What channels mean downstream
The channel name only becomes meaningful through the publishing plugins:
| Plugin | Default channel | Other channels |
|---|---|---|
@semantic-release/npm |
npm publish --tag latest |
--tag beta, --tag 1.x: users opt in with npm install app@beta |
@semantic-release/github |
a normal GitHub Release, marked latest | a GitHub pre-release for pre-release branches |
| exec / custom | ${nextRelease.channel} is available to your scripts (for example, to push app:beta image tags) |
When beta is merged and 2.0.0 is released, the npm plugin also moves latest to 2.0.0; the addChannel step exists for exactly these "promote an existing release to another channel" moves.
Test yourself
Two more fixes land on the beta pre-release branch after 2.0.0-beta.2. What gets released?
- 2.0.1
- 2.0.0-beta.3
- 2.1.0-beta.1
- Nothing until merge
A feat!: commit is pushed to the 1.x maintenance branch while main is at 2.0.0. What happens?
- 1.x releases 2.0.0
- The release fails: 2.0.0 is outside the 1.x range
- It releases 1.1.0
- It releases 3.0.0
How does an npm user get the beta?
npm install app(it's the default)npm install app@beta(the beta channel's dist-tag)npm install app --pre- They can't