Git allows you to add tags to commits. This can be very useful, for example to keep track of version numbers. Let’s say that we have a repository containing the code of an application. When we decide it is time to release version 3.6.9 it would be a good idea to tag the latest commit with that version number:
$ git tag 3.6.9
By default Git does not push your tags to remotes, so if you want to this you will have to add the option:
$ git push origin master --tags
To list all tags in the repository you can execute the following command:
$ git tag
You can also bring all the files in the repository back to the state of the tag:
$ git checkout 3.6.8
This can be very useful when you need to make a hotfix for a version that is already in production for example. When you found the culprit and are ready to start making changes, you can checkout a new branch from this state:
$ git checkout -b hotfix-description-of-problem