⚫ Git: Tag Overview ⚫

Git Tag is a powerful way of organising your git commits and history by setting markers in your git history.

In this thread, I'm going to cover everything you need to know about it and how to use it.

Let's get started. 🧵 👇 1/11
1️⃣ What is Git Tag?

By creating a tag in your git database, you're referencing a certain commit.

An example of using tags is marking specific releases of a codebase. E.G. V1.0

For example, when I've redesigned my website, I tag the different versions first commit. 2/11
2️⃣ Creating a new tag

To create a new tag, you use the syntax:

git tag <TAG NAME>

So an example would be:

git tag V1.0

This would create a new tag that is called V1.0 and references the current commit reference that HEAD is pointing to. 3/11
2️⃣ 2 Types of Tags

You get to 2 different types of tags:

👉 Annotated: full objects, extra metadata (date, email, tagger name), has a message, created -a flag.
👉 Lightweight: Created -lw flag & missing -a, -s, -m flags.

Generally, it is prefered to use Annotated tags. 4/11
3️⃣ Listing Tags

To list all of the tags in a current git database, use the command:

git tag

This will return all of the tags within the database.

You can also filter them using wildcards:

git tag -l <WILDCARD>

5/11
4️⃣ Tagging old commits

By default, the tag will point to the current commit ref that HEAD is pointing to.

You can change this by passing a specific commit ref to the command:

git tag -a v1.2 <COMMIT REF>

This will create a new annotated tag with the passed ref.

6/11
5️⃣ Replacing old tags/commits

If you try to create a duplicate tag name, git will error:

fatal: tag <TAG NAME> already exists

This also true if you point the tag at an old commit ref.

If you have to update an existing tag, use -f.

git tag -a -f v1.4 <COMMIT REF>

7/11
6️⃣ Sharing Tags

Like branches, git will not push tags, if you want to do this you have to explicitly pass it to git push:

git push origin <TAG NAME>

If you want to push multiple tags, you can use the --tags flag.

8/11
7️⃣ Checkout Out a Tag

You can check out a tag using:

git checkout <TAG NAME>

❗ This puts the repo in a detached HEAD state, meaning changes won't update the tag but will create a new detached commit & won't be part of a branch. Best practice is to create a new branch. 9/11
8️⃣ Deleting a Tag

You can easily delete a tag by using the -d flag like:

git tag -d <TAG NAME>

10/11
I hope you found this thread helpful. If you did please consider sharing it so others can find it helpful too.

If you like this content and want to see more, please consider following me. 😄

11/11
You can follow @MrConerMurphy.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: