A Step-by-Step Guide on How to Create a Tag in GitLab

Git tags serve as essential reference points in a project’s development history, allowing developers to mark specific commits with meaningful labels. Whether you’re marking a release version, a bug fix, or any other significant milestone, tags make it easy to revisit and manage different stages of your project. In this step-by-step guide, we’ll walk you through the process of creating tags in GitLab, both from the command line and the GitLab UI, ensuring you have all the tools you need to effectively utilize this powerful feature.

Key Takeaways

  • Understand the different types of Git tags and their benefits.
  • Learn how to set up your GitLab environment for tagging.
  • Master the commands for creating lightweight and annotated tags from the command line.
  • Discover how to create and manage tags using the GitLab UI.
  • Explore best practices and naming conventions for Git tags.

Understanding Git Tags

Tags in Git serve as references that point to specific moments in a repository’s history. They are commonly used to mark specific versions of a project for release, such as (v1.0, v2.0, and so on). A tag can be thought of as a static branch that remains unchanged once created. Unlike branches, which have a continuous history of commits, tags maintain a fixed position in the project’s timeline.

Git is an indispensable tool for developers and programmers, providing a robust version control system that allows for effective collaboration and efficient project management. Among the many features Git offers, tags hold a special place, offering a simple yet powerful way to mark specific points in your repository’s history. In this article, we’ll discuss the importance of Git tags, their utility in software development, and a step-by-step guide on how to use them effectively.

Setting Up Your GitLab Environment

Prerequisites for Tagging

Before you can start tagging in GitLab, there are a few prerequisites you need to meet. First, ensure you have a GitLab account and the necessary permissions to create tags in your project. If you don’t have a project yet, to get started, create a new project or use an existing one. Additionally, make sure Git is installed on your local machine and that you have a basic understanding of Git commands.

Connecting Your Local Repository to GitLab

To connect your local repository to GitLab, follow these steps:

  1. Clone your repository: If you haven’t already, clone your GitLab repository to your local machine using the command:
    git clone <repository_url>
  2. Navigate to your project directory:
    cd <project_directory>
  3. Add the GitLab remote: If your repository is not already connected to GitLab, add the remote URL:
    git remote add origin <repository_url>
  4. Verify the remote URL: Ensure that your local repository is correctly connected to GitLab by running:
    git remote -v

Setting up your GitLab environment correctly is crucial for a smooth tagging process. Make sure all configurations are in place before proceeding to create tags.

Creating a Lightweight Tag from the Command Line

Creating a lightweight tag in GitLab is a straightforward process that can be done directly from the command line. Lightweight tags are essentially pointers to specific commits and do not contain additional metadata like annotated tags.

Command Syntax

To create a lightweight tag, use the following command:

git tag <tagname>

Replace <tagname> with a descriptive name for your tag. For example:

git tag v1.0

Executing this command creates a lightweight tag identified as v1.0. Lightweight tags are created with the absence of the -a, -s, or -m options. Lightweight tags create a new tag checksum and store it in the .git/ directory of the project’s repo.

Pushing the Tag to GitLab

Once you’ve created the tag locally, the next step is to push it to your GitLab repository. Use the following command to push the tag:

git push origin <tagname>

Replace <tagname> with the name of your tag. For example:

git push origin v1.0

This command pushes the lightweight tag v1.0 to the remote repository on GitLab. After pushing, you can verify the tag in the GitLab UI under the repository’s tags section.

For a comprehensive guide on setting up GitLab on Windows, including configuring GitLab, creating a new project, and essential steps for smooth operation, refer to the official documentation.

Creating an Annotated Tag from the Command Line

developer using command line

Command Syntax with Message

To create an annotated tag, you can use the git tag command with the -a flag, which stands for ‘annotate’. This command allows you to add a message to your tag, providing additional context and metadata. Here’s the syntax:

git tag -a <TAG_NAME> -m "<MESSAGE>"

For example, to create an annotated tag named v1.0 with the message "Version 1.0", you would run:

git tag -a v1.0 -m "Version 1.0"

Alternatively, if you prefer to write a longer tag message, you can omit the -m flag and your default text editor will open for you to input the message:

git tag -a v1.0

Annotated tags are particularly useful for public releases or significant milestones, as they include additional metadata such as the tagger’s name, email, and date.

Pushing the Annotated Tag

Once you’ve created your annotated tag locally, the next step is to push it to your GitLab repository. Use the following command to push a specific tag:

git push origin <TAG_NAME>

For example, to push the v1.0 tag to the remote repository, you would run:

git push origin v1.0

Important: Make sure to push your tags to the remote repository to ensure they are available to all collaborators.

By following these steps, you can effectively create and manage annotated tags directly from the command line, adding valuable context to your project’s history.

Tagging a Specific Commit

Identifying the Commit SHA

To tag a specific commit, you first need to identify the commit’s SHA (Secure Hash Algorithm). This unique identifier can be obtained by running the git log --oneline command, which will list all commits in a concise format. Look for the SHA of the commit you want to tag.

Creating the Tag for the Commit

Once you have the commit SHA, you can create a tag for that specific commit. Use the following syntax:

git tag <tag_name> <commit_sha>

Replace <tag_name> with your desired tag name and <commit_sha> with the SHA of the commit you identified earlier. If you want to create an annotated tag, you can add the -a and -m options:

git tag -a <tag_name> <commit_sha> -m "message"

This command will create a tag with a message, making it easier to understand the purpose of the tag later on.

Pro Tip: Tagging specific commits is particularly useful for marking important milestones or releases in your project’s history.

Using the GitLab UI to Create Tags

Navigating to Your Project

To create a tag from the GitLab UI:

  1. On the left sidebar, select Search or go to and find your project.
  2. Select Code > Tags.

Creating a New Tag

  1. Select New tag.
  2. Provide a Tag name.
  3. For Create from, select an existing branch name, tag, or commit SHA.

Adding an Optional Message

  1. Optional. Add a Message to create an annotated tag, or leave blank to create a lightweight tag.
  2. Select Create tag.

Creating tags through the GitLab UI is a straightforward process that allows you to mark important points in your repository’s history with ease.

Naming Conventions for Tags

When it comes to naming your Git tags, following a consistent convention is crucial. This not only helps in maintaining clarity but also ensures compatibility with various tools and systems. GitLab enforces additional rules on tag names to maintain this consistency.

Viewing and Managing Tags in GitLab

To view all existing tags for a project:

  1. On the left sidebar, select Search or go to and find your project.
  2. Select Code > Tags.

In the GitLab UI, each tag displays:

  • The tag name.
  • Optional. If the tag is protected, a protected badge.
  • The commit SHA, linked to the commit’s contents.
  • The commit’s title and creation date.
  • Optional. A link to the release.
  • Optional. If a pipeline has been run, the current pipeline status.
  • Download links to the source code and artifacts linked to the tag.
  • A Create release link.
  • A link to delete the tag.

Listing tags allows you to quickly find a specific commit or project version. This tutorial shows how to list local and remote Git tags.

Automating Actions with Tags

Using Webhooks

The creation or deletion of a tag can be used as a trigger for automation. For instance, you can use a webhook to automate actions like Slack notifications or signaling a repository mirror to update. This can be particularly useful for keeping your team informed and your repositories synchronized.

Triggering CI/CD Pipelines

Tags can also be used to trigger CI/CD pipelines. By using the if: $CI_COMMIT_TAG condition in your pipeline configuration, you can ensure that specific jobs run only when a tag is created. This is a powerful way to automate deployments and other critical tasks.

Pro Tip: Consider setting deployment or release tags automatically to streamline your release process and ensure consistency across your projects.

Troubleshooting Common Tagging Issues

Tag Not Showing Up in GitLab

If your tag is not appearing in GitLab, it could be due to a few reasons. First, ensure that you have pushed the tag to the remote repository using the correct command. You can do this with:

git push origin <tagname>

If the tag still doesn’t show up, verify that you have the necessary permissions to push tags to the repository. Sometimes, tags might not appear immediately due to caching issues; in such cases, try refreshing the page or clearing your browser cache.

Tag Push Rejected

A tag push can be rejected for several reasons. One common issue is that the tag name conflicts with an existing branch name. To prevent this problem:

  1. Identify the branch names you do not want used as tags.
  2. As described in Configuring protected tags, create a protected tag:
    • For the Name, provide a name, such as stable. You can also create a wildcard like stable-* to match multiple names, like stable-v1 and stable-v2.
    • For Allowed to Create, select No one.
    • Select Protect.

Users can still create branches, but not tags, with the protected names.

Another reason could be that the tag is protected. In such cases, you need to have the appropriate permissions to push the tag. If you encounter this issue, contact your repository administrator to grant you the necessary permissions.

Unleashing efficiency with GitLab CI/CD pipelines can also be hindered by tagging issues. Ensure your tags are correctly configured to avoid disruptions in your CI/CD workflows.


Creating tags in GitLab is a straightforward process, whether you prefer using the command line or the GitLab UI. Tags serve as important markers in your project’s history, allowing you to easily reference specific points in your development timeline. By following the steps outlined in this guide, you can efficiently manage your project’s versions and releases. Remember, tagging is not just about marking a point in time; it’s about maintaining a clean and organized workflow that can significantly enhance your project’s development and deployment processes. Happy tagging!

Frequently Asked Questions

What is the difference between a lightweight tag and an annotated tag?

A lightweight tag is simply a name for a specific commit, while an annotated tag includes a message, the tagger’s name, and the date.

How do I push a tag to GitLab from the command line?

Use the command `git push origin ` to push a specific tag or `git push origin –tags` to push all tags.

Can I create a tag for a specific commit in GitLab?

Yes, you can create a tag for a specific commit by specifying the commit SHA when creating the tag either from the command line or the GitLab UI.

What are the benefits of using tags in Git?

Tags provide a way to mark specific points in your project’s history as important. They are often used to mark release points (e.g., v1.0, v2.0).

How do I delete a tag in GitLab?

To delete a tag in GitLab, navigate to the Tags section in your project, find the tag you want to delete, and click the delete button next to it.

What is Semantic Versioning in the context of Git tags?

Semantic Versioning is a convention for naming tags that conveys meaning about the underlying changes. It uses a three-part version number: MAJOR.MINOR.PATCH (e.g., v1.2.3).

Can I automate actions based on tags in GitLab?

Yes, you can use webhooks and GitLab CI/CD pipelines to automate actions such as deployments or notifications when a tag is created or deleted.

Why is my tag not showing up in GitLab after pushing it?

Ensure that you have pushed the tag to the correct remote repository using `git push origin ` or `git push origin –tags`. Also, refresh the GitLab Tags page.

You may also like...