Git tags
Git tag are used to label and mark a specific commit in the history.
In a Details, Git tags are labels that you can apply to a specific commit in your Git repository. They are commonly used to mark a specific version of your code such as a release or a stable version.
Although tag is similar to a branch but It points directly to a specific commit in the history.
There are two types of tags.
a. Light-weighted tag (a name only)
b. Annotated tag (allows you to add a message explaining the tag)
- To create a tag first, checkout to the branch where you want to create a tag.
git checkout <Branch name>
2. Create a tag:
git tag <tagname>
Example:
git tag v1.0 //create a tag named "v1.0"
You can also specify a commit hash to apply the tag to a specific commit:
git tag <tagname> <commit-hash>
Example:
git tag v1.0 abc123def456 //create "v1.0" tag on the commit "abc123def456".
To view a list of all tags in your repository, run:
git tag //This will display a list of all tags in your repository.
Display the details of a particular tag:
git show <tagname>
Example:
git show v1.0
git show tag <tagname>
is displaying the description of tag projectv1.0, such as author name and date.
3. Pushing tags to remote:
Then, you would push the tag to the remote repository.It will help other team members to know where to pick an update.
git push origin <tagname> //push tag
Example:
git push origin v1.0
git push origin --tags //push all tag
git push --tags
This would push the tag to the “origin” remote which is typically the name of the remote repository.
Now, you can easily refer to this specific version of your code using the tag. For example, if you wanted to create a branch for bug fixes on version 1.0.0 you could use the following command:
git fetch --all --tags //get all tag locally
git checkout -b bug_fixes v1.0 //create new_branch(bug_fixes)
Now we can see all tags by clicking on it. It will show as:
We can download it as a zip and tar file.
All Command:
git checkout master //where you want to create a tag
git tag <tag-name> //create tag
git tag -a <tag_name> -m "message" //create a tag with Message
git tag <tagname> <commit-hash> //create a tag from an older commit
git tag //view all tag
git tag -l ".*"
git tag -l <string>.* //Search Git Tags
git show <tagname> //details of a particular tag
git push origin <tagname> //push tag
# --all will fetch all the remotes.
# --tags will fetch all tags as well
git fetch --all --tags --prune //for get all tag locally
git tag -d <tag_name> //delete tag
git tag -d <tag1> <tag2> //delete multiple tag
git push origin -d <tagname> //delete remote tag
git push origin -d <tag1> <tag2> //delete multiple remote tag