0
0
GitHow-ToBeginner · 3 min read

How to Create a Release from a Tag in Git

To create a release from a tag in Git, first create a tag with git tag on the desired commit, then push it using git push origin <tag-name>. You can then use this tag to mark a release point in your project history.
📐

Syntax

Here is the basic syntax to create and push a tag in Git:

  • git tag <tag-name>: Creates a lightweight tag on the current commit.
  • git tag -a <tag-name> -m "message": Creates an annotated tag with a message.
  • git push origin <tag-name>: Pushes the tag to the remote repository.
bash
git tag -a <tag-name> -m "Release message"
git push origin <tag-name>
💻

Example

This example shows how to create an annotated tag named v1.0.0 and push it to the remote repository to mark a release.

bash
git tag -a v1.0.0 -m "Release version 1.0.0"
git push origin v1.0.0
Output
Total 0 (delta 0), reused 0 (delta 0) To origin * [new tag] v1.0.0 -> v1.0.0
⚠️

Common Pitfalls

Common mistakes when creating releases from tags include:

  • Creating a tag locally but forgetting to push it to the remote repository, so others cannot see the release.
  • Using lightweight tags instead of annotated tags, which lack metadata like author and message.
  • Tagging the wrong commit by not checking the current HEAD or commit hash.
bash
## Wrong: creating a lightweight tag without message

git tag v1.0.0

git push origin v1.0.0

## Right: creating an annotated tag with message

git tag -a v1.0.0 -m "Release version 1.0.0"
git push origin v1.0.0
📊

Quick Reference

Summary tips for creating releases from tags in Git:

  • Use annotated tags (-a) for releases to include metadata.
  • Always push tags to the remote repository with git push origin <tag-name>.
  • Verify the commit you tag with git log or git show <commit>.
  • Use semantic versioning for tag names like v1.0.0 for clarity.

Key Takeaways

Create annotated tags with git tag -a <tag-name> -m "message" to mark releases.
Push tags to remote with git push origin <tag-name> so others can access the release.
Check the commit you tag to avoid marking the wrong code version.
Use clear, semantic version names for tags to communicate release versions.
Avoid lightweight tags for releases because they lack important metadata.