Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you configure git to automatically fetch the tags on every pull?

Tags:

git

This may or may not be a very dumb idea, but how can you configure a git repository such that any pull that is done automatically fetches the tags from the other repository as well?

According to the docs, it looks like you can do this on a per remote reposistory basis:

remote.<name>.tagopt
Setting this value to --no-tags disables automatic tag following when fetching from remote <name>. Setting it to --tags will fetch every tag from remote <name>, even if they are not reachable from remote branch heads. Passing these flags directly to git-fetch(1) can override this setting. See options --tags and --no-tags of git-fetch(1).

Is there way to make --tags the default flag to fetch for every fetch?

like image 750
Ross Rogers Avatar asked Sep 21 '12 15:09

Ross Rogers


People also ask

Does git pull fetch all tags?

git fetch fetches all branch heads (or all specified by the remote. fetch config option), all commits necessary for them, and all tags which are reachable from these branches. In most cases, all tags are reachable in this way.

How do I fetch all the tags?

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.

How do you git fetch and pull?

Git Fetch is the command that tells the local repository that there are changes available in the remote repository without bringing the changes into the local repository. Git Pull on the other hand brings the copy of the remote directory changes into the local repository.

How do you fetch in git?

When you do a git fetch, it fetches all the changes from the remote repository and stores it in a separate branch in your local repository. You can reflect those changes in your corresponding branches by merging. So basically, git pull = git fetch + git merge.


1 Answers

Fetching tags has a different effect than fetching commits (git fetch), as explained in "Does “git fetch --tags” include “git fetch”?".

The latter will update branch heads, and will actually fetch tags reachable from those updated branches.
The former will fetch all tags, but won't update the branch heads.

So if your tags are reacheable from the branches you are fetching, you don't have to include --tags by default.

Considering the large history of some repos (including the linux one), always wanting to fetch all tags might lead to tag list cluttering (a list of tag pollutted by hundreds of not-needed tags).


Note that starting git 1.9/2.0 (Q1 2014), git fetch --tags will fetch everything (like git fetch), plus the tags. See "Does “git fetch --tags” include “git fetch”?".

Request that all tags be fetched from the remote in addition to whatever else is being fetched.

So you can try the remote.<name>.tagOpt config option:

git config (--global) remote.<name>.tagOpt --tags

Setting it to --tags will fetch every tag from remote <name>, even if they are not reachable from remote branch heads.

like image 152
VonC Avatar answered Sep 19 '22 15:09

VonC