A branch is a label that moves forward with every commit. A tag is a fixed name for one commit, such as v1.1.0, and it never moves. GitHub builds its releases on top of tags. Once you see which names move and which don’t, the route from a feature branch to a released version makes sense.

I worked this out at work while getting a feature branch ready for its first push and the release after it.

From a feature branch to a version

MAINDEVELOPFEATUREv1.0made from v1.0your commitspull request, reviewmerge commitversion bumpPR to main,CI runsv1.1.0deploythis tagMerges are merge commits, so the feature's commits stay grouped under one merge in the history.

Features gather on a shared develop branch. When it’s time for a version, the maintainer merges develop into main, and that merge commit gets the version tag. Some teams skip develop and merge features straight into main. The tag on the merge is the same either way. A server is then deployed from the tag, not from a branch, because a branch will have moved on by tomorrow.

Six things that look alike

NameWhat it is
BranchA moving label for work in progress. Every new commit moves it forward.
TagA fixed name for one commit, such as v1.1.0. It never moves.
ReleaseA GitHub page built on a tag, with notes on what changed and optional files to download.
PackageA built product, such as a Docker image, stored on GitHub.
Archive tagA habit, not a feature: a tag on history you want to keep but will never merge.
CI runGitHub running the checks on a fresh machine and reporting a tick or a cross.

Version tags should be annotated tags, made with git tag -a. An annotated tag stores who made it, when and a message, which is what a release needs. A lightweight tag is only a name pointing at a commit.

Keeping history you will never merge

Sometimes a branch holds history you want to keep but can’t publish, for example early commits with real data in them. Rewrite a clean branch for the push, and keep the old history under an archive tag on your laptop. A plain git push sends no tags, so the archive can’t leak by accident. (The push.followTags setting would send annotated tags on commits you push, but the archive’s commits are never pushed.)

The tag only protects the history while the laptop exists. For a second copy, git bundle packs the history into one file, and you can store that file somewhere private. Running git clone on the bundle file brings the whole history back.

Habits that keep it tidy

  • Rewrite before pushing, never after. --fixup, rebase and --amend all give commits new IDs. That’s fine on your laptop. Once a branch is on GitHub and under review, fix things with new commits, and the pull request updates by itself.
  • Search the history, not just the files. git grep searches today’s files only. Piping git log -p for the range you are about to push through grep searches every commit in it, which is what a push publishes.
  • Push a version tag by name, such as git push origin v1.1.0, and only after the merge into main.
  • Never move a pushed tag. If a tag is wrong, make a new one, v1.1.1, rather than pointing v1.1.0 somewhere else. Other people’s copies still hold the old meaning.
  • Reading is always safe. git log, git show v1.0, git tag --list and git status only look.

git push --tags publishes every tag you have

It sends all your tags at once, archive tags included, and a pushed tag stays in other people’s clones even if you delete it later. Push version tags one at a time, by name.

Related: ci-cd-and-checks