Skip to content

Instantly share code, notes, and snippets.

@paulschick
Created June 20, 2023 20:00
Show Gist options
  • Save paulschick/b4aad5235a901bec169ff02c3ddc9c3f to your computer and use it in GitHub Desktop.
Save paulschick/b4aad5235a901bec169ff02c3ddc9c3f to your computer and use it in GitHub Desktop.
Git Tag Cheat Sheet

Git Tag Cheat Sheet

List Tags

List all the tags in the repository:

git tag

List tags with a specific pattern:

git tag -l "v1.0.*"

Create Tags

Lightweight Tags

Create a lightweight tag (like a branch that doesn’t change):

git tag <tagname>

Example:

git tag v1.0.0

Annotated Tags

Create an annotated tag (stored as full objects in the Git database):

git tag -a <tagname> -m "<tag message>"

Example:

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

Create a tag for a specific commit:

git tag -a <tagname> <commit-hash> -m "<tag message>"

Example:

git tag -a v1.0.0 9fceb02 -m "Release version 1.0.0"

Push Tags

Push a single tag to remote repository:

git push <remote> <tagname>

Example:

git push origin v1.0.0

Push all tags to remote repository:

git push <remote> --tags

Example:

git push origin --tags

Checkout Tags

Checkout code at a specific tag:

git checkout <tagname>

Example:

git checkout v1.0.0

Delete Tags

Delete a tag in the local repository:

git tag -d <tagname>

Example:

git tag -d v1.0.0

Delete a tag in the remote repository:

git push <remote> --delete <tagname>

Example:

git push origin --delete v1.0.0

Show Tag Information

Show information about a specific tag:

git show <tagname>

Example:

git show v1.0.0

Signing Tags

Create a signed tag (if you have a GPG setup):

git tag -s <tagname> -m "<tag message>"

Example:

git tag -s v1.0.0 -m "Signed release version 1.0.0"

Verify Signed Tags

Verify tags are signed and valid:

git tag -v <tagname>

Example:

git tag -v v1.0.0

Note: Always use annotated tags for marking releases or important points in history as they are checksummed and can include additional information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment