Similarly, if you want your tag to be annotated, you can still use the “-a” and “-m” options to annotate your tag. $ git tag HEAD~1 (for two commits before HEAD) $ git tag HEAD~1 (for the commit before HEAD) In order to create a Git tag for the last commit of your current checked out branch, use the “git tag” command with the tag name and specify “HEAD” as the commit to create the tag from. If you want to create a Git tag from the last commit, there is a shorter syntax that you can use : the HEAD syntax. $ git log -onelineĬab6e1b (tag: v1.0, origin/master) master : initial commitĪwesome, you have successfully created a tag for a specific commit in your Git history.
Next, run the “git log” command again to make sure that your commit was correctly tagged. In order to create an annotated tag for the first commit in your Git history, you would execute the following command $ git tag -a v1.0 cab6e1b -m "Tagged the first commit with v1.0" $ git log -onelineĬab6e1b (origin/master) master : initial commit $ git tag -a -m "message"Īs an example, let’s say that you want to create an annotated commit for the first commit of your Git history.įirst, list the commits SHA by using the “git log” command with the “–oneline” option to get short commits SHA. If you want to create an annotated tag for a specific commit, you can use the “-a” and “-m” options we described in the previous section. In order to create a Git tag for a specific commit, use the “git tag” command with the tag name and the commit SHA for the tag to be created. In some cases, you may want to create a Git tag for a specific commit of your Git history. Great, now your tags pushed to your remote repository and your colleagues can start fetching it. $ git push -tagsįor example, given the tags that you created in the previous section, you would get the following output $ git push -tags To push your newly created tags, use the “git push” command and specify the “–tags” to explicitly push tags to your remote Git repository.
$ git tag v2.0.0 Push your created tagsīy default, the “git push” command does not automatically push your tags to your remote repository. In your latest commit, you introduced a code-breaking change, as a consequence you are going to increment the major version number.
patch : is an increment for a bug fix or a patch fix done on your software.įor example, let’s say that you are currently working on the version 1.0.0 of your software.minor : is a version number that is compatible with previous versions.major : is a version number where you introduced breaking modifications (modifications of your new version are NOT compatible with previous versions).
Semantic versioning is quite easy to understand : you want to name tags as versions of your software in the form of v. However, there are some best practices when it comes to naming Git tags : using semantic versioning. When naming tags, the Git CLI does not put any constraints on the name of your Git tag. You can verify that your Git tag was successfully created by running the “git tag” command with the “-n” option. To achieve that, you would run the following command $ git tag -a v3.0 -m "New release for v3.0" Note : if you don’t provide the “-m” option, your default text editor will open in order for you to type the tag message.Īs an example, let’s say that you want to create a new annotated tag on your master branch with the message “New release for v3.0” To create a Git tag with a message, use the “git tag” command with the “-a” option for “annotated” and the “-m” option for message. You would not create a commit without a commit message, you would not create a Git tag without a message. Create Tag with MessageĬreating tags is great but you will need to add a description to your tag in order for other contributors to understand why you created it. You have successfully created a tag on Git. To verify that your Git tag was successfully created, you can run the “git tag” command to list your existing tags.