Git Foundations / Work With a Remote

Mark versions with tags

Lesson 27 of 33. Open to read. No account needed.

Names That Do Not Move

A branch name moves forward with every commit. Sometimes you need a name that stays put: "the version we released", "what we sent to the printer". That is a tag: a fixed name for one commit. Tags are commonly used for release versions, such as v1.0.

Two Kinds of Tag

git tag -a v1.0 -m "First team handbook"   # annotated tag
git tag draft-2                             # lightweight tag
git tag                                     # list tags
git show v1.0                               # show a tag and its commit
  • An annotated tag (-a) is stored as its own object with the tagger's name, a date and a message. git show displays those before the commit. Use annotated tags for releases and anything others rely on.
  • A lightweight tag is just a name pointing at a commit, with no message or tagger. It suits quick private bookmarks.

Without a commit name, a tag marks the commit you are on. Add a commit name or ID at the end to tag another one. Each tag name can be used once; Git refuses a second v1.0 with tag 'v1.0' already exists.

Tags Are Shared Separately

git push sends branches, not tags. A new tag stays in your clone until you push it by name:

git push origin v1.0      # push one tag
git push origin --tags    # push all your tags

On the other side, git fetch and git pull bring in tags that point at the commits they download, reporting * [new tag].

Looking at a Tagged Version

To see the files as they were at a tag, switch to it with a detached HEAD:

git switch --detach v1.0

git status says HEAD detached at v1.0. You can look around and run the project as it was. To go back, switch to a branch. Plain git switch v1.0 refuses, because a tag is not a branch; older guides use git checkout v1.0, which detaches in the same way.

Exercise: Publish and Use a Release Tag

Asha marks the current team handbook as version 1.0 and shares the tag. Ravi fetches it and later looks back at that version.

Starting state: Git configured as in the configuration lesson. You will rebuild the team practice set.

  1. Rebuild the practice set:

    cd ~/git-practice
    rm -rf team
    mkdir team
    cd team
    git init --bare -b main shared.git
    git clone shared.git asha
    cd asha
    git config user.name "Asha Rao"
    git config user.email "asha@example.com"
    cat > README.md <<'EOF'
    # Team notes
    
    We meet on Mondays.
    Bring your laptop.
    EOF
    git add README.md
    git commit -m "Add team notes"
    git push -u origin main
    cd ..
    git clone shared.git ravi
    cd ravi
    git config user.name "Ravi Kumar"
    git config user.email "ravi@example.com"
    cd ..
    
  2. As Asha, tag the current commit and look at the tag:

    cd asha
    git tag -a v1.0 -m "First team handbook"
    git tag
    git show v1.0
    

    git tag lists v1.0. git show v1.0 starts with tag v1.0, a Tagger: Asha Rao line, the date and the message, then shows the commit.

  3. Push the branch, and check whether the shared repository has the tag:

    git push
    git ls-remote --tags origin
    

    git push says Everything up-to-date, and git ls-remote --tags origin, which lists the tags in the remote, prints nothing: the tag was not shared. Push it by name:

    git push origin v1.0
    

    Git reports * [new tag] v1.0 -> v1.0.

  4. As Ravi, fetch and list tags:

    cd ../ravi
    git fetch
    git tag
    

    The fetch reports * [new tag] for v1.0, and git tag lists it.

  5. The project moves on. Asha adds a line and shares it, and Ravi pulls:

    cd ../asha
    cat >> README.md <<'EOF'
    Room 4 is booked for us.
    EOF
    git commit -am "Add meeting room"
    git push
    cd ../ravi
    git pull
    
  6. As Ravi, look at version 1.0, then return:

    git switch --detach v1.0
    git status
    cat README.md
    git switch main
    

    git status says HEAD detached at v1.0, and README.md has no line about Room 4: it is the version Asha tagged. After git switch main, the newest version is back.

Success: Ravi saw v1.0 after fetching and could switch to the tagged version.

If something differs:

What you seeLikely causeNext step
The tag is missing in Ravi's cloneThe tag was never pushedgit push origin v1.0 in Asha's clone, then fetch again
fatal: a branch is expected, got tag 'v1.0'git switch needs --detach for a taggit switch --detach v1.0
tag 'v1.0' already existsThe name is takenChoose a new name, such as v1.1
git show has no Tagger: lineIt is a lightweight tagCreate releases with git tag -a
  1. Keep the practice set for the next lesson.

Independent task: as Asha, mark the newest commit with a lightweight tag named draft-2 and share it. As Ravi, fetch it, then compare what git show draft-2 prints with git show v1.0.

Check Your Understanding

  1. Asha created v1.1 and ran git push, which said everything was up to date. Ravi fetches but sees no v1.1. Why?
  2. Why do teams prefer annotated tags for releases?

Answer and Reasoning

Independent task

git tag draft-2
git show draft-2
git push origin draft-2
cd ../ravi
git fetch
git tag

Run the first three commands in asha. Ravi's git tag lists draft-2 and v1.0. git show draft-2 begins straight away with the commit, because a lightweight tag has no tagger, date or message of its own. git show v1.0 first shows tag v1.0, the tagger, the date and "First team handbook".

Understanding check

  1. git push sends branches, not tags, so v1.1 never reached the shared repository. Asha needs git push origin v1.1, or git push origin --tags.
  2. An annotated tag records who made it, when and why, which matters for a version other people depend on. A lightweight tag is only a name.

References

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 99 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy