In this post, let's do an experiment with git tag command options. In GitOps we need to know what is a tag? How many types of git tags? We will learn about Creating, deleting, and listing tags for a project repository. Once everything is done, we need to know how to push the tag to the remote repository.
Work tree for git tag creation |
Why git tagging?
- Tagging is used to mark a commit stage as important
- We can tag a commit for future references
- Typically tagging wiil be used to book mark release points in a Project.
- Annotated tags will be recommend where you are working in team and collaborating for a project development.
Before you start on git tag
You must have a GitHub or GitLab account to work on a remote repository. Knowledge of basic repository creation on these Git clouds. On your git client shell (git bash as well) you must create the global user identity entries in the configurations.
[vagrant@mydev tags_handson]$ git config --list user.email=bhavanishekhar@gmail.com user.name=Pavan Devarakonda core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true # Now let's begin mkdir tags_handson cd tags_handson/ git init echo "test1"> test1.txtEnter some text into the test1.txt file.
What is git tag?
Git Tags are a simple aspect of the Git version control system, they allow you to identify specific release versions of your application code. You can think of a tag as a branch that doesn't change. Once the git tag is created, it loses the ability to change the history of commits.
Git supports two types of tags:
- Annotated Tags: Annotated tags, however, are stored as full objects in the Git database.
- Lightweight Tags: A lightweight tag is very much like a branch that doesn’t change — it's just a pointer to a specific commit.
How to Create tags in Git?
To create a new tag execute the following command
Annotated tags store extra metadata such as Author name, Release notes, tag-message, and Date as full objects in the Git database. All this data is important for the public release of your project.
Tags can also include a more descriptive tag-message or annotation much like a commit message when you are about to merge. Usually, this is achieved by using (-a for annotation):
git tag -a v1.1 -m 'annotated tag test'
Lightweight tagging
git tag v1.0
How to delete the tags from the local and remote repo?
Example:
git tag -d v1.0Note: If you try to delete a non existig Git tag, there will be the following error:
git push --delete origin remote_tag_name
git push --delete origin v1.0.0-rc1
Listing tags
git tag
Listing git tags |
git tag -l '*rc*'
git log --tags --simplify-by-decoration --pretty="%ai %d"
How to push tags?
git push origin v1.0
To push all tag use following command:
git push origin --tagsor
To push all the tags to remote (not recommended):
git push --tags
Run this to push mytag to a project that is hosted on GitHub or GitLab on git origin
git push origin refs/tags/mytagBest practice using the refs/tags instead of just specifying the
To push annotated tags and current history chain tags use:
git push --follow-tagsThis flag --follow-tags pushes both commits and only tags that are both:
Annotated tags (so you can skip local/temp build tags) Reachable tags (an ancestor) from the current branch (located on the history)
Now...
In order to checkout a git tag , you would execute the following command
git checkout tags/tag-name -b branch-name eg as mentioned below.
git checkout tags/v1.0 -b v1.0-branch
To fetch the all tags use the command with git fetch:
git fetch --all --tags
git tag cheat sheet
In my understanding about git tag is like branch but cannot move.
1 comment:
Thanks pavan sir for giving good information about git tags
Post a Comment