How do you push a tag to a remote repository using Git?

To push a Git tag to a remote repository, use the following commands depending on your goal:

1. Push a Specific Tag

git push <remote-name> <tag-name>

Example:

git push origin v1.0.0

2. Push All Tags

git push <remote-name> --tags

Example:

git push origin --tags  # Pushes all local tags to the remote "origin"

Key Notes

  • Remote Name: Replace <remote-name> with the remote repository (e.g., origin).
  • Force Push (Use with Caution):
  git push -f origin <tag-name>  # Overwrites remote tag (risky!)
  • Delete a Remote Tag:
  git push origin :refs/tags/<tag-name>

Example:

  git push origin :refs/tags/v1.0.0  # Deletes the tag "v1.0.0" on the remote

Example Workflow

  1. Create a Tag:
   git tag -a v1.0.0 -m "Release version 1.0.0"
  1. Push the Tag:
   git push origin v1.0.0

Why This Works

  • Tags are not automatically pushed with git push (unlike branches).
  • Use explicit commands to sync tags to remotes (e.g., GitHub, GitLab).

Verification

Check remote tags:

git ls-remote --tags origin

Leave a Reply

Your email address will not be published. Required fields are marked *