Skip to content

make sure tags are up-to-date when using fetch

The drawback of the default "fetch" option is that tags are usually not fetched. This makes things like using git describe in build/packaging/deploy steps basically unusable unless you choose the "clone" option.

At first it seemed like the simple fix would be to add the --tags option to the git fetch command so that tag objects (annotated tags) are also fetched. See https://git-scm.com/docs/git-fetch

To be safe, it would probably be a good idea to prune refs/tags as well... So that if a tag is deleted in the repo, it will be properly reflected in the ci runner repo.

Unfortunately simply adding --prune additionally will not prune already existing tags in the local repo. According to the git documentation tags are pruned IFF they are explicitly given in the refspec.

So it seems that the "safest" method is to to do something like: git fetch origin --prune "+refs/heads/*:refs/remotes/origin/*" "+refs/tags/*:refs/tags/*"

where the +refs/heads/*:refs/remotes/origin/* is the "default" refspec and equivalent to only running git fetch. The additional + is to ensure that the ref is updated even if it doesn't result in a fast-forward update.

Merge request reports