Tags make a point as a specific point in Git history. Tags are used to mark a commit stage as relevant. We can tag a commit for future reference. Primarily, it is used to mark a project’s initial point like v1.1.
- When we want to create a release point for a stable version of your code we use git tag or
- When we want to create a historical point that you can refer to reuse in the future.we create tag
- Tags are much like branches, and they do not change once initiated.
- We can have any number of tags on a branch or different branches
- Tags are named like v0.1, v1.0…
Git Tag Types :
1. Annotated tag :
- It’s tag that store some more info that usual tag, such as Developer name , email, date and some info message
Example : git tag <tag name> -m ” <Tag message> -a <developer-x1>
2. Light-Weighted Tag :
- It does not store more information and makes it light-weight.
Example :git tag <tag name>
git tag project-v1.0
Git Tag Commands :
| 1 | Git Creating Annotated tag | git checkout <Branch name> git tag <tag name> -m ” <Tag message> -a <developer-x1> git tag project-one-v0.1 -m “Version 0.1” -a “Developer-x1” |
| 2 | Git Create tag | git checkout <Branch name> git tag <tag name> git tag project-v1.0 |
| 3 | Git List Tag | git tag or git show |
| 4 | To see Specific tag info | git tag show project-v1.0 |
| 5 | List tags with filter pattern | git tag -l “<pattern>.*” git tag -l “project-one*” |
| 6 | Deleting Tags | git tag –d <tagname> or git tag –d project-v1.0 |
| 7 | Delete a Remote Tag | git push origin -d <tagname> |
| 8 | Delete Multiple Tags | git tag -d <tag1> <tag2> |
| 9 | Git Checkout Tags with branch | git checkout -b < new-branch-name> <tag-name> |
| 10 | Create a tag from an older commit: | git tag <tagname> < commit-hash> git tag <project-one-v2.2> 6tgf877ytd |
| 11 | Renaming tag | (i) Create new tag : git tag <new_tag_name> <old_tag_name> Example : git tag v1.7 v1.6(ii) Delete old tag : git tag -d <old_tag_name> Example : git tag -d v1.6 (iii) Pushing the tag : git push origin <new_tag_name> :<old_tag_name> Example : git push origin v1.8 :v1.7 |
| 12 | Cleaning the tags collaborators may still have the old tag, this command update the tags on contributors computers | git pull –prune –tags |
Pushing the tags to github :
| 13 | Pushing One tag to github | git push origin <tagname> |
| 14 | Pushing all tags at once | git push origin –tags |
| 15 | Deleting a remote tag | git push origin -d <tagname> |
| 16 | Deleting Multiple remote tags | git push origin -d <tag1> <tag2> |