0 votes
1 view
in DevOps and Agile by (30k points)

I want to force push, for example, my tag 1.0.0 to my remote master branch.

I'm now doing the following:

git push production +1.0.0:master

I want to force the push because all I care about is that the code inside the 1.0.0 tag is pushed to the master branch on the remote repository.

What am I doing wrong?


After running git tag -l from inside the remote Git repository, I see that master is listed, meaning that when I ran the following:

git push production 1.0.0:master

It actually pushed the tag and created a tag named master rather than a new branch.

I want to basically push the contents of the tag 1.0.0 into the master branch of the remote Git repository.

1 Answer

0 votes
by (51.2k points)

This may probably fail because 1.0.0 is an annotated tag. You might have seen the following error message:

error: Trying to write a non-commit object to branch refs/heads/master

Annotated tags have their distinct type of object that points to the tagged commit object. 

Branches will not point to tag objects, only commit objects. 

You need to “peel” the annotated tag back to commit object and push that, for this use:

git push production +1.0.0^{commit}:master

git push production +1.0.0~0:master       # shorthand

There is another syntax that will work in this case:

git push production +1.0.0^{}:master

Reference: https://git-scm.com/docs/git-rev-parse#_specifying_revisions 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !