Skip to main content
  1. Learn
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Git collaboration
  6. Tagging
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

Tagging

In Git, tagging is a way to label specific points in the commit history of a repository. Tags serve as static references to important milestones, releases, or significant versions of the codebase. They can be used to mark specific commits, branches, or even entire repositories.

There are two types of Git tags:

  • Lightweight tags
  • Annotated tags

A lightweight tag is similar to a branch that does not change. It just points directly to a specific commit in the history. Lightweight tags are mainly used temporarily in your local workspace.

An annotated tag is checksummed and often used when planning to mark an important commit. You can add a message, signature, date, and the tagger’s name and email.

Git tags in the main branch
Git tags in the main branch.

Best practices for tagging

When it comes to tagging in Git, following best practices helps ensure consistency, clarity, and effective use of tags. Consider the following best practices for tagging in Git:

  • Use Semantic Versioning (SemVer): Consider adopting Semantic Versioning principles for tagging version releases. SemVer uses a three-part version number (e.g., major.minor.patch) to indicate compatibility and communicate the significance of changes in the release. This makes it easier to understand the scope and impact of the tagged versions.
  • Create annotated tags for releases: For important milestones or significant releases, use annotated tags rather than lightweight tags. Annotated tags contain metadata like the tagger's name, email, date, and a message, providing valuable context about the release.
  • Use descriptive and consistent tag names: Choose descriptive and meaningful names for tags to easily identify their purpose or significance. It's advisable to use a consistent naming convention to ensure clarity and consistency throughout the repository. This could include incorporating versions, release names, or other meaningful identifiers.
  • Tag stable points in the commit history: Tags should be applied to stable points in the commit history, such as specific commits or merge commits that represent completed, tested, and reliable code. Avoid tagging branches that are still in active development and subject to frequent changes.
  • Tag important commits or milestones: Apart from version releases, consider tagging important commits, milestones, or significant changes in the history. For example, you can tag commits that fix critical bugs, introduce major features, or mark project milestones.
  • Document tags and releases: Maintain documentation that captures the purpose and details of each tag or release. This documentation can include release notes, changelogs, or a dedicated README section highlighting the significant changes or updates associated with each tag.
  • Push and share tags: Publish tags to remote repositories by using the git push --tags command. This ensures that the tags are accessible to other team members and can be used for collaboration, release management, or deployment processes.
  • Consider tag security and integrity: Consider signing tags with GPG (GNU Privacy Guard) keys to ensure the authenticity and integrity of the tags, especially for security-sensitive projects or public repositories.

By adhering to these best practices, you can leverage the power of Git tags effectively, create a clear release history, and enable efficient communication and collaboration within your team or community.

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life