Reputation: 722
When pushing to the master, I read that it is recommended to use:
git tag -a <tag name> -m <message> ; git push --tags
I added a new tag, and pushed the changes to the master, now I modified another file and want to push it to the master with the same tag.
I do: git push --tags -f
, I get "Everything up-to-date" message. but when I do: git status
I still see that: "Your branch is ahead of 'origin/master' by 2 commits"
why it is so ? what I have to do to add the new changes to the tag ?
Upvotes: 1
Views: 1425
Reputation: 16517
When you run a git push
, several things happen:
master
on the remote machine) is updated to point to the latest commitorigin/master
on the local machine) is updated to reflect the change on the remote branchBy specifying --tags
, you modify the behavior to update only the tag reference (plus some other references you may have specified on the command-line, but you didn't). If you tagged the latest commit, then this commits and all its ancestors were pushed, but you didn't go through steps 2 and 3 above. As a consequence
git status
uses the remote-tracking branch to determine whether you're ahead of the remote, it will tell you that you are ahead of the remote.The simplest solution is to run two pushes:
git push
to push your branches as usual (as specified by push.default
, i.e. push the current branch to the configured upstream if it has the same name with recent Git)git push --tags
to push your tags (will take almost no time since the commits are already pushed, Git just needs to create the tag on the remote repository)If you want to do both at the same time, then see the answers to the question Push git commits & tags simultaneously.
Note that there's no reason to create a tag for each of your pushes. Usually, people create tags only for releases.
Upvotes: 1
Reputation: 476554
You need to push with
git push --all
and if there are new tags, with:
git push --all; git push --tag
Not git push --tags
. --tags
will push all references of tags, not commits on the master branch. I don't know where you have read this advice, but tagging constantly is not really encouraged. Normally you tag when you have a new release of your software. In other words a major milestone. Not for an ordinary commit.
Furthermore I would strongly discourage using the -f
(also known as --force
) flag (fully) automatically. If the repositories are out of sync, it is better not to force your commits over the shared repository. If there are warnings, you must try to resolve them, not overrule these warnings immediately.
General advice is to learn to use a tool instead of following a few steps without realising what is going under the hood.
EDIT:
You probably received an error when you added the tag a second time:
fatal: tag 'foo' already exists
(with foo
the name of the tag). As the statement says, you can't simply tag with the same name twice. git push --tags
commits content up to that tag. Since you assigned the tag with a previous commit, you will push up to that commit, not the latest. You can do a few things:
git push --tags
;git tag -f -a <tag name> -m <message>
. In that case the old tag is removed. And git push --tags
will work. The problem is that usually tags are used to specify a release. Users might say: aha, the latest release is release-2.3
, I don't have to update the software whereas the new release-2.3
is different from the old one. Annotating with release-2.3-fix0
might make them aware you fixed something.git push --all
to push the commit up to the heads of all branches.Background
You can see your commit graph like:
A -- B -- C -- D
/
<tag>
If you call git push --tag
, it will synchronize A
, B
and C
because that's the last commit under the supervision of <tag>
. If you retag, the tag will be assigned to D
instead.
Upvotes: 1