Video in progress
What is a tag in Git, and how does it differ from a branch?
A tag is also a pointer to a commit, but it stays fixed in one place: it does not move when you make new commits. It is usually used to mark release versions, for example v1.4.0.
📖 Answer
A branch is a moving pointer that advances with every commit. A tag is a permanent mark saying "this commit is version 1.4.0".
git tag -a v1.4.0 -m "Release 1.4.0" # annotated tag
git push origin v1.4.0 # tags are not pushed automatically
git tag # list
git switch --detach v1.3.2 # look at the code of an old version
There are two kinds of tags: lightweight (git tag v1.4.0), which is just a name, and annotated (-a), which stores the author, date and a message, and can be signed. For releases it is better to use annotated tags.
In practice a tag triggers CI: when a v* tag is pushed, the pipeline builds the artifact and labels the Docker image with that version.
Sign up to mark studied questions and save your progress.