Push git commits & tags simultaneously
I'm aware of the reason that git push --tags
is a separate operation to plain old git push
. Pushing tags should be a conscious choice since you don't want accidentally push one. That's fine. But is there a way to push both together? (Aside from git push && git push --tags
.)
Update May 2015
As of git 2.4.1, you can do
git config --global push.followTags true
If set to true enable --follow-tags option by default. You may override this configuration at time of push by specifying --no-follow-tags.
Update April 2013
Since git 1.8.3 (April 22d, 2013), you no longer have to do 2 commands to push branches, and then to push tags :
The new " --follow-tags
" option tells " git push
" to push relevant annotated tags when pushing branches out .
You can now try, when pushing new commits:
git push --follow-tags
That won't push all the local tags though, only the one referenced by commits which are pushed with the git push
.
Git 2.4.1+ (Q2 2015) will introduce the option push.followTags
: see "How to make “ git push
” include tags within a branch?".
Original answer, September 2010
The nuclear option would be git push --mirror
, which will push all refs under refs/
.
You can also push just one tag with your current branch commit:
git push origin : v1.0.0
You can combine the --tags
option with a refspec like:
git push origin --tags :
(since --tags
means: All refs under refs/tags
are pushed, in addition to refspecs explicitly listed on the command line )
You also have this entry "Pushing branches and tags with a single "git push" invocation"
A handy tip was just posted to the Git mailing list by Zoltán Füzesi:
I use .git/config
to solve this:
[remote "origin"]
url = ...
fetch = +refs/heads/*:refs/remotes/origin/*
push = +refs/heads/*
push = +refs/tags/*
With these lines added git push origin
will upload all your branches and tags. If you want to upload only some of them, you can enumerate them.
Haven't tried it myself yet, but it looks like it might be useful until some other way of pushing branches and tags at the same time is added to git push.
On the other hand, I don't mind typing:
$ git push && git push --tags
Beware , as commented by Aseem Kishore
push = +refs/heads/*
will force-pushes all your branches .
This bit me just now, so FYI.
René Scheibe adds this interesting comment:
The --follow-tags
parameter is misleading as only tags under .git/refs/tags
are considered.
If git gc
is run, tags are moved from .git/refs/tags
to .git/packed-refs
. Afterwards git push --follow-tags ...
does not work as expected anymore.
上一篇: Git:在一个命令中推动两个回购
下一篇: 同时推git提交&标签