For the last months, I am making use of git tagging a lot, usually creating a tag and pushing it to the repo and rarely deleting it. This is a quick and dirty article stating my most used tagging commands for further reference.

Overview

In this quick article we'll see:

  1. What is tagging in Git
  2. Cheatsheet
    • Create a tag
    • Push a tag
    • Delete a tag

Just keep in mind that for this article I understand that you are familiar with git and what is it for, as I'm going to jump directly to one of its functionalities. To know more about git you can read this article in the official documentation: Getting Started - What is git?

1. What is a tag in git?

Git Tagging is the ability of marking a specific point in the respository's history, as stated in the official documentation. To make it more understandable, we want to mark a point in the list of commits of the codebase for a further use, for example as a version. We want to say "at this point of time, everything works well together, so I mark it as the version 123"

Tags are useful as one can relate to them externally. For example having a python library in a repository, we can relate to a point in time as a version, and use that version to ensure that it works good with our code.

See this line in a requirements.txt file of a program in python:

git+https://github.com/XaviArnaus/pyxavi@v0.1.2

The program will use the code in the git repository https://github.com/XaviArnaus/pyxavi that is tagged with the version 0.1.2. I can still keep on working in the library, adding more features and even remove stuff, and tagging all of these with new versions, but as long as the program relate to that 0.1.2, the git repository will return the code state by then. Very useful.

2. Cheatsheet

One more time: this is my cheatsheet for git tagging. For a more elaborated and full reference for git tag please head to the official documentation.

Create a tag

From the main branch. Make sure that all references to the version are up-to-date (docs, READMEs, tom files...). This creates a tag in local.

$ git tag -a v0.1.2 -m "v0.1.2"
  • The first version is the tag itself (with the -a).
  • The second is the message that will appear (with the -m). Can be a longer string, I don't use it.

Push a tag

This pushes a defined local tag to the remote repository

$ git push origin v0.1.2

Delete a tag

Once the tag is pushed, you need to delete it from remote AND from local. It is done separately. I personally do first the remote one and then the local one.

Delete a remote tag

This only affects the remote repository, not the local

$ git push --delete origin v0.1.2

Delete a local tag

This only affects the local code, not the remote repository

$ git tag --delete v0.1.2

Previous Post Next Post