Git tags are references that mark a specific commit as significant, most commonly used to label release versions so they can be found and checked out easily later.
Key Points: • git tag <tagname> <commit-id> creates a lightweight tag, essentially a fixed pointer to that commit. • Annotated tags, created with git tag -a, store extra metadata like the tagger's name, date, and a message, and are recommended for releases. • Tags aren't pushed automatically; use git push --tags or git push origin <tagname> to share them with the remote. • Semantic versioning conventions like v1.2.0 are commonly used for tag names to make releases easy to identify. • Unlike branches, tags don't move as new commits are added, making them ideal for marking a stable, unchanging snapshot.
Example: After merging the final commit for a release, the team runs git tag -a v2.1.0 -m "Release 2.1.0" and pushes it, so anyone can later run git checkout v2.1.0 to get exactly that release.
Code Example:
git tag -a v2.1.0 -m "Release 2.1.0"
git push origin v2.1.0Interview Tip: A concise interview answer is:
"I create annotated tags with git tag -a to mark release points, since they store metadata like the author and message, and push them explicitly with git push --tags. Tags give a stable, unmoving reference to a specific release, unlike branches which keep moving forward."