This is an example of how my git repo is right now:
v1.0 v1.1 v1.2 | | | a - b - c | | master HEAD
I usually commit, tag and push tags like this:
git commit -a -m "Commit msg"
git tag -a v1.3 -m "Tag msg"
git push --tags
The main problem I have is that the master branch doesn't move to the latest tag, so I'm always in a Detached HEAD state. Is there any way to fix this so the master branch will be always pointing to the latest pushed tag?
In order to find the latest Git tag available on your repository, you have to use the “git describe” command with the “–tags” option. This way, you will be presented with the tag that is associated with the latest commit of your current checked out branch.
In order to create a new tag, you have to use the “git tag” command and specify the tag name that you want to create. As an example, let's say that you want to create a new tag on the latest commit of your master branch. To achieve that, execute the “git tag” command and specify the tagname.
In order to checkout the latest Git tag, first update your repository by fetching the remote tags available. As you can see, you retrieve multiple tags from your remote repository. Then, retrieve the latest tag available by using the “git describe” command.
In this particular case, I had to do the following:
git branch -b exp
git merge -s ours master
git checkout master
git merge exp
Now master is the same as latest tag:
v1.0 v1.1 v1.2
| | |
a - b - c
|
HEAD
|
master
git commit -a -m "Commit msg"
git tag -a v1.4 -m "Tag msg"
git push master --tags
This way we avoid being in a Detached HEAD mode and the master branch is updated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With