Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace remote tag with Git

Tags:

git

branch

tags

I have some tags on my "origin" repository. Then I realized I needed to add some changes on one of the tags, and push them back on my repository. Is there a way I can push an existing tag to the repository in one time, or should I delete the tag before ?

like image 363
azmeuk Avatar asked Nov 19 '13 15:11

azmeuk


People also ask

How do I remove a remote tag?

In order to delete a remote Git tag, use the “git push” command with the “–delete” option and specify the tag name. To delete a remote Git tag, you can also use the “git push” command and specify the tag name using the refs syntax.

Can we update tag in git?

We are required to delete/update branches or delete/update files etc. Similar to this, sometimes, we are required to update the tags in Git. Updating a tag will take your tag to another commit. For example, we can update the tag v1.

How do I switch to a specific tag in git?

To switch to a commit-like object, including single commits and tags, use git switch --detach <commitish> , where <commitish> is the tag name or commit number.

How to delete remote Git tags?

How to Delete Remote Git Tags 1 Deleting a remote Git tag ¶. 2 Describing Git Tags ¶. Git tags allow tagging specific points in the history of repository and return to them later. 3 Git Push Origin and Git Push ¶. The git push command implicitly pushes your work to a remote repository. By default,... More ...

How do I push a tag to a remote Git repository?

By default, the git describe command ignores “lightweight” tags. Push Tag to Remote: The git tag command creates a local tag with the current state of the branch. When pushing to a remote repository, tags are NOT included by default. It is required to explicitly define that the tags should be pushed to remote.

How to rename a Git tag without checking it out?

git tag -a -m "`git cat-file -p old_tag | tail -n +6`" new_tag old_tag^ {} git push --tags git tag -d old_tag git push origin :refs/tags/old_tag You can also rename remote tags without checking them out, by duplicate the old tag/branch to a new name and delete the old one, in a single git push command.

How do I fix Git tag-D not found?

$ git tag -d v2.0 error: tag 'v2.0' not found. If you want to make sure that tags were correctly deleted, simply list your existing tags using the tag command and the “-l” option. In order to delete a remote Git tag, use the “git push” command with the “–delete” option and specify the tag name.


2 Answers

This should not be the practice, though you can delete the tag and push the change to the remote repo.

git tag -d tag1 git push origin :refs/tags/tag1 
like image 120
Bijendra Avatar answered Sep 18 '22 12:09

Bijendra


So if you need to move a tag (eg: "v0.5") on a git branch (eg: "master") to a different commit, probably a newer one, then you can use the -f option to git tag:

-f --force  Replace an existing tag with the given name (instead of failing) 

You probably want to use -f in conjunction with -a to force-create an annotated tag instead of a non-annotated one.

Example

  1. Delete the tag on any remote before you push

    git push origin :refs/tags/<tagname> 

    or for our example:

    $ git push origin master :refs/tags/v0.5 To [email protected]:org_name/repo_name.git - [deleted]         v0.5 
  2. Replace the tag to reference the most recent commit (using -f will save as the git tag -d <tagname> local tag deletion step).

    git tag -fa <tagname> 

    or for our example:

    $ git tag -fa "v0.5" -m "version 0.5" Updated tag 'v0.5' (was f55c93f) 
  3. Push the tag to the remote origin

    git push origin --tags 

    or for our example:

    $ git push origin master --tags Counting objects: 1, done. Writing objects: 100% (1/1), 196 bytes | 0 bytes/s, done. Total 1 (delta 0), reused 0 (delta 0) To [email protected]:org_name/repo_name.git * [new tag]         v0.5 -> v0.5 
like image 34
Exequiel Barrirero Avatar answered Sep 20 '22 12:09

Exequiel Barrirero