git: create tag and push to remote: why tag is behind master on remote?
Asked Answered
A

2

6

I did fork a bower package on github since I need some enhancement and mantainers do not react to pull requests.

I changed a bit bower.json (to change the name, the version and to add myself among the authors), applied my enhancements, added a new tag, and pushed (I need a new tag since bower repository does publish new packages versions on new tags only).
Then I have registered the forked package on the bower repo, with the modified name.

I do not use branches, to avoid complications: everything on master branch (I'm the only developer, and currently the only user of the package...).

So far, everything is good under the sun.

Now, my problem (for sure due to my limited knowledge of git): when I have to make a change on the forked bower package, I do:

  • apply my changes to the sources
  • mark the changes with a tag: git tag -a v1.2.3 -m "my latest enhancement"
  • commit and push: git add -A && git commit -m "committing my latest enhancement" && git push --tags origin master

Then, if I check my repository in github, I see master branch updated (with the latest enhancements), but if I switch to the latest tag (say, "1.2.3"), It is not up-to-date... This way, the changes are not available for bower users (only myself, currently... :-).

How is my work flow flawed?
How my understanding of tags is flawed?

Amling answered 4/7, 2016 at 13:34 Comment(0)
O
17

It seems that you tagged first and committed later.

You should first commit your work, and then when you tag it, it will apply to the latest commit.

The full flow is:

  • Apply your changes and then:
  • Update bower.json 'version' field

.

git add -A
git commit -m "My changes"
git tag -a v1.2.3 -m "My last tag"
git push --tags origin master

You can always use visual tool such as 'gitk' to see where the tag is actually pointing at.

Ockham answered 4/7, 2016 at 13:38 Comment(3)
So, the flow should be: change, add, commit, tag, push, enjoy. Right?Amling
I hate visual tools. Remember me of my sad windoze days... :-)Amling
You can also use the --decorate option to the log command to see where stuff is pointing at. log --oneline --decorate --graph e. g. is a useful alias I bound it to git alias lo (for "log oneline") and get a nice view on the commandline, or log --oneline --decorate --graph -n 10 as loh (for "log oneline head") to show only the 10 topmost commits. If you add --all as parameter it even shows all branches and tags. (Or --tags for all tags or --remotes for remotes, ...)Coprolalia
R
0

It's better not to use git push --tags

Use next command in terminal:

tagName=<enter your tag>; git tag $tagName; git push origin tag $tagName

It would create a tag with tagName and push it to remote named origin


Also you can create an alias (function) in bash_aliases:

gtp() {
    git tag $1
    git push origin tag $1
}

Using:

gtp 1.0.0 - will create and push tag 1.0.0 to origin

Raptorial answered 18/9, 2024 at 11:48 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.