23 | Handling Remote Tags and Branches |
You can push your tags to a remote repository by one of two mechanisms: you can call git push and supply the tag name as the reference to push, or you can add the --tags parameter to git push to push all your tags to the remote.
Most tags are fetched automatically. Fetching changes from master that has several tags in its history causes Git to fetch those tags as well. Like git push --tags, you can explicitly fetch tags via git fetch --tags.
Be careful with tags, however. Remote tags always win when there are two tags with the same name. For example, consider if your repository has a v1.0 tag that points to a specific commit, and your remote repository has a v1.0 tag that points to a different commit. When you pull changes from that remote, your v1.0 tag is going to change to reflect the latest.
The best way to handle this is through procedure. Determine who is responsible on your team for tagging commits and the way you’re going to name tags,[16] and stick to it.
You have to explicitly push a branch to get a local branch to show up on a remote repository. Likewise, you have to explicitly delete remote branches to remove them.
You can delete remote branches with a special-case refspec and git push :<branch to delete>. This is the equivalent of pushing an empty branch to the remote repository.
What To Do... |
| prompt> git push origin v1.0 |
| Total 0 (delta 0), reused 0 (delta 0) |
| To git://internal.domain51.pvt/sample-repo.git |
| * [new tag] v1.0 -> v1.0 |
| prompt> git push --tags origin |
| Total 0 (delta 0), reused 0 (delta 0) |
| To git://internal.domain51.pvt/sample-repo.git |
| * [new tag] v0.8 -> v0.8 |
| * [new tag] v0.9 -> v0.9 |
| prompt> git fetch --tags origin |
| remote: Counting objects: 42, done. |
| remote: Compressing objects: 100% (37/37), done. |
| remote: Total 42 (delta 18), reused 0 (delta 0) |
| Unpacking objects: 100% (42/42), done. |
| From git://internal.domain51.pvt/sample-repo.git |
| * [new tag] v0.8 -> v0.8 |
| * [new tag] v0.9 -> v0.9 |
| * [new tag] v1.0 -> v1.0 |
| prompt> git push origin :beta |
| From git://internal.domain51.pvt/sample-repo.git |
| - [deleted] beta |
Task 18, Tagging Milestones
[15] |
Most commands that require a remote repository take both remote names—what you add with git remote add—or the repository URL. |
[16] |
Semantic Versioning (http://semver.org/) is a great place to start. |
3.144.30.178