0

I am trying to make sense to myself about tagging with git. As far as understand tagging serves the purpose of marking certain points in development.

What I don't understand is – as far as I understand the documentation – that one can have entirely different tags for the same revision or version remote and local.

Let's say I am commiting my version and I tag it like

git tag v0.0.1 master

locally.

Now I am going to push my local commit to the remote repo. And since I might just have a bad day, I am messing up my remote tag with a typo like

git push origin master v0x.0.3

A few commits later I can't find my remote commit v0.0.1 anymore because of the typo.

I there no way I can tell git to use the tag I am using locally also on the remote repo?

LongHike
  • 4,016
  • 4
  • 37
  • 76

1 Answers1

2

It sounds like you're saying that when you do that push, you think it's going to create a new remote tag at master with a different name than your local tag. That's not correct.

If a ref named v0x.0.3 exists, it will be pushed as is (not necessarily pointing to master). If it doesn't - which is likely in the case of random fat-fingering as suggested by the command examples you suggest - it will cause the push command to error out with a message saying that it doesn't know what v0x.0.3 is.

Now, it's true that you can create a local tag on a commit independent of any tags the remote has pointed at that commit. For that matter, you can have any number of local tags all pointed at the same commit, any number of which may or may not have been shared with the remote.

If you actually wanted to create a tag of a different name on the remote, you could; but I don't believe for one second that you'd do it accidentally.

git push origin local_tag_name:remote_tag_name

(because local_tag_name is a tag so git will infer that you want remote_tag_name to be a tag as well, but you have to go out of your way to change the name); or

git push origin master:refs/tags/remote_tag_name

(where you explicitly say that you want to create a new tag on the remote).

And there are use cases where you might want to do that. In almost all situations, git provides the flexibility to do whatever you want, and then provides eas(ier)-to-use commands to do what most people want most of the time. So your observation that you can create different tag names on the remote is correct; but that doesn't mean you have to, or should, or are going to be accidentally tricked into doing so.

To align this with git concepts: Although you seem to be thinking of a tag as an attribute of a commit, it is not. It is its own thing (which happens to refer to a commit[1]); and that thing might or might not exist in any given repo. IF it exists locally, you can (but don't have to) push it to a remote; and if it exists in a remote, you can (but don't have to) fetch it to the local.


[1] Actually a tag happens to refer to some object, which is usually a commit but could be something else, e.g. a specific file

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52