Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does pushing a git tag also push the commit?

Tags:

git

github

Here's what I did...

git checkout -b test-branch
### add a line of text to a .md file, then...
git commit -am 'a commit that will never be pushed'
git tag my-tag
git push --tags
### NOTE: I ONLY pushed the tag (not the branch)

So...

I have not pushed the commit

I have not pushed the branch the commit is on

But...

When I view the tag in github

Then click on the associated SHA enter image description here I see the actual (un-pushed) commit

enter image description here

I thought a Tag was only a pointer to a SHA.

How is it I am seeing the contents of an un-pushed commit? And what is going on?

like image 891
sfletche Avatar asked Jul 18 '26 18:07

sfletche


1 Answers

I have not pushed the commit

Yes you have, whether you know it or not, otherwise the remote would reject the tag.

You never "push the commits" manually, you push them implicitly while pushing a branch or tag that references the commits. Tags and branches are more or less identical. Commits are not "on branches", anymore than they are "on tags". Branches and tags are pointers to commits, and when you push one of either type, the commits it references must also be pushed.

The same way you don't have to ask Git to specifically download all the commits when you check out a branch. Git does this for you.

I thought a Tag was only a pointer to a SHA (not a container for commits...)

Yes, exactly the same as a branch. They're both just pointers to commit IDs.

like image 67
meagar Avatar answered Jul 21 '26 07:07

meagar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!