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...
  • Push tag v1.0 to the origin.
     
    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
  • Push all tags to the origin.
     
    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
  • Fetch remote tags and update local tags.
     
    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
  • Delete the remote branch called beta.
     
    prompt>​ git push origin :beta
     
    From git://internal.domain51.pvt/sample-repo.git
     
    - [deleted] beta

Related Tasks

Footnotes

[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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.59.198