Backlog uses cookies to deliver our services. By visiting our website, you agree to the use of cookies as described in our Cookie Policy.

Preliminary preparation

Let's create a new directory and initialize a new empty repository. For this example, we will create a directory with the name "tutorial".

$ mkdir tutorial
$ cd tutorial
$ git init
Initialized empty Git repository in /Users/eguchi/Desktop/tutorial/.git/

Create a file with the name myfile.txt in the tutorial directory. Put in the text content below and commit it.

Git commands even a monkey can understand
$ git add myfile.txt
$ git commit -m "first commit"
[master (root-commit) a73ae49] first commit
1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 myfile.txt

At this point, the revision history should look like this.

Current history

Add a lightweight tag

Use the tag command to add a new tag. Enter a tag name in <tagname>.

$ git tag <tagname>

Run the following command to add a tag named "apple" to HEAD.

$ git tag apple

Running tag without any parameters gives you a list of tags in this repository.

$ git tag

To see the history log with tag information, executing "log" with the --decorate option.

$ git log --decorate
commit e7978c94d2104e3e0e6e4a5b4a8467b1d2a2ba19 (HEAD, tag: apple, master)
Author: yourname <>
Date: Wed Jul 18 16:43:27 2012 +0900

    first commit
Add a tag "apple" to the commit indicated by the current HEAD.

Add an annotated tag

We can add an annotated tag by running "tag" with the -a option, which opens the default text editor that lets you add notes to the tag.

You can also pass the -am option instead if you want to add the note alongside the tag creation.

$ git tag -a <tagname>

Run the following command to add a tag for HEAD named "banana" with some notes.

$ git tag -am "Git Beginner's Guide for Dummies" banana

Passing in the -n option gives you the list of tags with their notes for this repository.

$ git tag -n
apple first commit
banana Git Beginner's Guide for Dummies
Add a tag with an annotation "banana" to a commit which HEAD is pointing
  out now.