How do I push all annotated tags?

How can I pull all annotated tags from my local repo to the remote one without pushing light tags?

I am using lightweight tags locally which I do not need so git push --tags

there is no solution.

I know git push --follow-tags

, but this will only push tags that are related to the commits that are currently being pushed.

I need this option because my normal workflow includes from time to time, but only tagging when a release ends, and I sometimes forget to push the tag. This issue often goes unnoticed for a long time and causes some confusion with other developers as we get out of sync with our tags.

Since it is difficult to list which annotated tags exist locally but not remotely, I would like to solve this problem by simply pushing all local annotated tags, which ensures that all developers' local and remote repositories have the same annotated tags.

+3


source to share


2 answers


It's not too difficult. Find all annotated tags first (rejecting tags that point directly to commits, not annotated tag objects). It's a little longer, so you can write it as a shell function:

list_annotated_tags() {
    git for-each-ref --format '%(objecttype) %(refname)' refs/tags |
        while read reftype refname; do
            case $reftype in tag) echo $refname;; esac
        done
}

      

Read the result above and use them as refspec for the command git push

:



git push origin $(list_annotated_tags)

      

and your script is complete.

+4


source


I noticed that my light tags are not including taggerdate

. In this case, this will work on the command line or in a script:

taglist=`git for-each-ref refs/tags --format '%(refname:short) %09 %(taggerdate:short)' | \
grep -E '[0-9]{4}-[0-9]{2}-[0-9]{2}' | \
cut -f 1 | \
tr '\n' ' '`

      

and then:

git push origin $taglist

      



A summary of the commands for anyone interested:

  • 1st line - Retrieves a list of tags git for-each-ref

    , formatted to display the tag, tab and date. (Only annotated tags will have a date.)
  • Second line - the command grep

    searches through the results of the first command, pulling only those date tags. Command
  • 3rd row - cut

    removes everything after the start column (i.e. from each tab following each tag to the newline

    end of each row of the result).
  • 4th line - the command tr

    replaces with a newline

    space in the final results. (Tags are now on the same line, separated by spaces.)

The results are stored in a variable ( taglist

- note the back exits at the beginning and end of the entire command set after taglist=

).

Finally, you drag the tag list to the top (using $

to indicate what taglist

the variable is).

+1


source







All Articles