Clue Mediator

Using tags in Git

📅June 14, 2021
🗁Git

Today we’ll give you an understanding of the tags and show you a list of git commands to play with tags.

Checkout more articles on Git

Tagging in Git

  1. Create a light-weighted tag
  2. Get tag list
  3. Search tags using patterns
  4. Create a annotated tag
  5. Push tag to the remote repository
  6. Checkout tag
  7. Delete tag locally
  8. Delete tag remotely
  9. Create a new branch from tag

1. Create a light-weighted tag

To create a tag, run the following command. It’s also known as a light-weighted tag.

git tag <tag_name></tag_name>

Make sure you will checkout the branch where you want to create a tag.

The above tag command will create a mark point on the branch as `<tag_name>`.

2. Get tag list

We can list the available tags in our repository using following command.

git tag

Use the following command to check the details of a particular tag.

git tag show <tag_name></tag_name>

3. Search tags using patterns

You can also search the list of tags using patterns.

git tag -l "<patterns>*"

// Example
git tag -l "ver*"</patterns>

4. Create a annotated tag

Annotated tags are tags that store extra metadata like developer name, email, date, and more.

git tag <tag_name> -m "<tag_message>"</tag_message></tag_name>

5. Push tag to the remote repository

Use the following command to push the particular tag to the remote repository.

git push origin <tag_name></tag_name>

Use the `--tags` to push all the tags to the remote repository.

git push origin --tags

6. Checkout tag

Run the following command to checkout the perticular tag.

git checkout <tag_name></tag_name>

7. Delete tag locally

Use the following command to delete a tag locally.

git tag -d <tag_name></tag_name>

8. Delete tag remotely

After deleting the tag from local, you can still see the tag on remote repository. So run the following command to delete a tag from a remote repository.

git push origin -d <tag_name></tag_name>

9. Create a new branch from tag

If you want to create a new branch from a specific tag then use the following command.

git checkout -b <branch_name> <tag_name></tag_name></branch_name>

I hope you find this article helpful.
Thank you for reading. Happy Coding..!! 🙂