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
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
| Name | What it is |
|---|---|
| Branch | A moving label for work in progress. Every new commit moves it forward. |
| Tag | A fixed name for one commit, such as v1.1.0. It never moves. |
| Release | A GitHub page built on a tag, with notes on what changed and optional files to download. |
| Package | A built product, such as a Docker image, stored on GitHub. |
| Archive tag | A habit, not a feature: a tag on history you want to keep but will never merge. |
| CI run | GitHub 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,rebaseand--amendall 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 grepsearches today’s files only. Pipinggit log -pfor the range you are about to push throughgrepsearches 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 intomain. - Never move a pushed tag. If a tag is wrong, make a new one,
v1.1.1, rather than pointingv1.1.0somewhere else. Other people’s copies still hold the old meaning. - Reading is always safe.
git log,git show v1.0,git tag --listandgit statusonly look.
git push --tagspublishes every tag you haveIt 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