Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: distinguish between local and remote tags

Tags:

git

git-tag

tags

If there are tags in the remote repository, I'm usually getting them automatically when pulling. When I delete the created local tag (git tag -d <tag-name>) and pull, the deleted tag will be recreated. I can delete remote branches/tags (git push <remote-branch/tag-name>:<branch/tag-name>), but how can I detect that the local tag was created by fetching a remote tag?

like image 661
Mot Avatar asked Mar 31 '11 07:03

Mot


People also ask

How can I tell the difference between local and remote?

You can git branch -a to list all branches (local and remote) and then choose the branch name from the list (just remove remotes/ from the remote branch name. Example: git diff main origin/main (where "main" is the local main branch and "origin/main" is a remote, namely the origin and main branch.)

What is the difference between local and remote in git?

The local repository is a Git repository that is stored on your computer. The remote repository is a Git repository that is stored on some remote computer.

How do I check remote tags?

As a consequence, you may have not fetched some tags that have been made available by other developers on your repository. In order to list remote Git tags, you have to use the “git ls-remote” command with the “–tags” option and the name of your remote repository.

How do I fetch all tags from a remote?

To fetch tags from your remote repository, use “git fetch” with the “–all” and the “–tags” options. Let's say for example that you have a tag named “v1. 0” that you want to check out in a branch named “release”. Using this command, you have successfully checked out the “v1.


1 Answers

If you're annoyed about these tags being recreated when you run git pull, you turn off the fetching of tags by default with the remote.<remote-name>.tagopt config setting. e.g. if the remote is origin, then you can do:

git config remote.origin.tagopt --no-tags 

Update: to address your comment, the reason that I suggest this is that there's not an obvious way to tell the difference between a tag that was created locally and one that was fetched from a remote. There's also no reflog for tags. So, my suggestion is to suppress automatic fetching of tags - you can then fetch them yourself into a different namespace. For example, you could do:

git fetch origin +refs/tags/*:refs/tags/origin/* 

... and perhaps create an alias for that. Then when you want to fetch tags, they'll be named, for example, refs/tags/origin/tag1 instead of refs/tags/tag1.


If you want this to happen automatically, you could change your .git/config to list multiple refspecs for fetching, e.g.:

 [remote "origin"]       url = whoever@whereever:whatever.git       fetch = +refs/heads/*:refs/remotes/origin/*       fetch = +refs/tags/*:refs/tags/origin/* 

... which is suggested in Pro Git.

like image 116
Mark Longair Avatar answered Oct 04 '22 09:10

Mark Longair