How to Create tags in Git

“Lightweight” tags in Git are simply pointers to specific commits. You can create a lightweight tag on the command line using: git tag <tag name>. This will create a local tag on the current branch.

Listing Tags in Git

To list the tags you have previously created use: git tag.

For repositories with many tags it may be useful to find tags by name. This is possible with Git using globbing and the -l option. For example, git tag -l "v-1.*" will list all the tags starting with “v-1.”.

Pushing Tags to a Remote

Tags are not pushed to the remote repo by default, so in order to push a tag to the remote repository use: git push origin <tag name>.

To push all tags to the remote repo use: git push origin --tags.

Checking out Tags

There is no straight forward way to checkout a tag in Git. But you can checkout the specific commit associated with a tag that into a new branch. This will give you a working directory that looks like the specified tag. Here is a simple example of checking out the v1.0.0 tag into the v1 branch: git checkout -b v1 v1.0.0

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">