1

I don't understand how to tag a version properly in git so the version is pushed to github together with the tag.

In fact I don't even know which is the right moment for setting the the tag name.

Do I need to set the tag before the local commit or after the local commit?

I've seriously checked the git documentation.

And then, when I want to push to remote i.e. github do I explicitly need to set the tag name again like in this example:

https://stackoverflow.com/a/5195913/716568

Is there no way to automatically push in sync with the currently set local tag?

LongHike
  • 4,016
  • 4
  • 37
  • 76

2 Answers2

4

I found two ways to do this.

1.

$ git add .
$ git commit -m "a msg"
$ git push origin master tag v1.0.0

2.

$ git add .
$ git commit -m "msg"
$ git tag v1.0.1
$ git push origin master --tags

You can add a message to a tag like this:

$ git tag v2.0.0 -m "second release"
$ git push origin master tag v2.0.0

But as far as I can tell the only way to have a tag show as the latest release is to add a title to it on github.com

You can find more info with $ git help tag and $ git help push

1

The right moment for setting tag name is when you create the tag. And you can create and push it at any time. You can create a tag immediately after commit or a week later. Up to you.

When you want to push tag(s) with commits either you name the tags in the command line (git push origin master tag v3.42, for example) or you can add push.followTags=true to config: git config [--global] push.followTags true ([--global] means optional — you have to decide if you want the settings in your global config (per-user) file or local (per repo)); with this setting git pushes tags when it pushes commits pointed to by these tags.

You may push a tag alone: git push origin tag v3.42. Git will push the tag and all commits required to complete the branch.

phd
  • 82,685
  • 13
  • 120
  • 165