Tags
Tags in Git serve as bookmarks for important commits, providing a human-readable name that maps to a commit hash.
Why use tags? Imagine you've just finished a major milestone of your project, say version 1.0. You can mark this point in your repository history for future reference. With this reference, you can easily switch your working tree back to this state at any time. You could also compare your current code with the code at that prior version.
Tags are also useful for marking public release versions. Want an example?
Say you developed a currency conversion library and released it to the public. Lots of people started using your library in their projects. You've got fame and recognition!
After a while, you released new updates, which changed the library's API in a major way. All the other projects downloaded the new version of your library and put it in their code as is. Sadly, their own code wasn't updated yet to support your new API, so all of their integrations instantly got broken. Suddenly, half of the Internet is on fire, all thanks to you!
By using tagged releases, you can avoid this problem. When you release your code for the first time, you mark it as version 1.0, so the other projects can make a reference to this specific version. Then, if you make major changes, you can mark the new version as 2.0. People who used the old version can still keep using it. Those who are ready to upgrade can switch their dependencies to your version 2.0. This is a pretty basic scheme, but there's a more elaborate versioning strategy called semantic versioning.
Let's tag our latest hello.html
as version 1.0
.
git tag 1.0
Tag the latest commit as version 1.0
using the command above.
Great, the tag is created. Now, let's list all tags in our repository. You can do that by running git tag without any arguments.
List all tags in your repository using the git tag
command.
Hi! I'm Alex, creator of GitByBit.
This page is a part of the interactive course about Git version control.
It's a one-of-a-kind course that is integrated into the VS Code code editor. Learning directly in VS Code lets you operate Git exactly as you would in real life, doing real jobs, writing real code.
In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.
The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.