乐闻世界logo
搜索文章和话题

How do you push a tag to a remote repository using git

2个答案

1
2

When you want to push a local Git tag to a remote repository, you can use the git push command to accomplish this. There are two main scenarios: pushing a single tag or pushing multiple tags. Below I will explain the operation methods for both.

Pushing a Single Tag to a Remote Repository

Assume you have already created a local tag v1.0. To push this tag to the remote repository, use the following command:

shell
git push origin v1.0

Here, origin is the default name for the remote repository, and v1.0 is the tag name you want to push. After executing this command, the tag v1.0 will be pushed to the remote repository.

Pushing All Newly Created Local Tags to a Remote Repository

If you want to push all newly created local tags to the remote repository at once, use:

shell
git push origin --tags

This command pushes all newly created local tags to the origin remote repository. Note that this command does not push deleted tags.

Example

Assume you are releasing a project version and create a tag named v2.0 to mark this release:

shell
git tag v2.0

After creating the tag, confirm it can be pushed to the remote repository for team sharing:

shell
git push origin v2.0

This way, your team members can obtain this specific project snapshot by pulling the remote tag.

If your team has adopted a versioning strategy and you have a series of tags (e.g., v1.1, v1.2, v2.0, etc.) that need to be pushed together, you might choose to push all tags:

shell
git push origin --tags

This is how to push Git tags to a remote repository.

2024年6月29日 12:07 回复

git push --follow-tags

This is a sensible option introduced in Git 1.8.3:

shell
git push --follow-tags

It pushes two commits and only pushes tags that meet the following conditions:

  • annotated
  • reachable from the pushed commit (ancestors)

This is sensible because:

For these reasons, --tags should be avoided.

Git 2.4 added the push.followTags option, which enables this flag by default. You can set it using the following command:

shell
git config --global push.followTags true

Alternatively, add followTags = true to the [push] section in your ~/.gitconfig file.

Visual Studio Code

"git.followTagsWhenSync": true to activate this feature in Visual Studio Code, set the variable according to user or workspace settings. GitHub

2024年6月29日 12:07 回复

你的答案