This is a quick tutorial on how to create a Tag in Git
Creating the Tag in Git is important because it gives the ability to mark or point to a repository's history.
Basically, we will release the tag once the new version is deployed and finalized. By doing so, if we need the previous Tag version code, we can create a new branch from this tag and use the branch for further manipulation.
Create a Tag:
Before creating the tag make sure to switch to the branch where we want to create a Tag. Use the following command to switch the branch.
git checkout development
Here, development is the branch name to switch, use your own branch name.
git tag -a v0.0.1-06-07-2022 -m "version 0.0.1 released"
This will create the tag with the name v0.0.1-06-07-2022; please use your own version name and "version 0.0.1 released" as a message
List the Tag:
Now, let's list the available tags created.
git tag
We can see all the created tag output below.
v0.0.1-06-07-2022
Push to the repository:
Once the tag is created it will available only locally. If we are using a code management service provider like Github, Bitbucket, or Gitlab then we need to push the tag to a point on the repository. Use the following command to push
git push origin v0.0.1-06-07-2022
Once the tag is pushed we can see the output similar to below
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 176 bytes | 176.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://bitbucket.org/repo_name.git
* [new tag] v0.0.1-06-07-2022 -> v0.0.1-06-07-2022
Delete the Tag:
Let's first delete the tag created from the remote.
git push --delete origin v0.0.1-06-07-2022
Once the tag is deleted we can see the output similar as below
To https://bitbucket.org/repo_name.git
- [deleted] v0.0.1-06-07-2022
Now, let's delete the tag from locally
git tag -d v0.0.1-06-07-2022