When I try to push all branches and tags to a remote, git emits the following error:
# git push origin --all --tags
fatal: --all and --tags are incompatible
However, this works:
# git push origin refs/heads refs/tags
Everything up-to-date
Questions:
Why git names push-all-branches --all
but not --branches
or --heads
? git push origin --all
only pushes branches, not all refs. What's the philosophy behind such naming? Does this mean tags are really 2nd-class citizens in a Git repo?
Why git doesn't allow the use of both --all
and --tags
?
PS. I know there's a --follow-tags
option. I know pushing all tags is not recommended by some people, but this thread is not about that.
man git-push
:
--all
Push all branches (i.e. refs under refs/heads/); cannot be used with other <refspec>.
--tags
All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line.
By default, git push will not push tags. Tags have to be explicitly passed to git push . To push multiple tags simultaneously pass the --tags option to git push command.
This process is just like sharing remote branches — you can run git push origin <tagname> . If you have a lot of tags that you want to push up at once, you can also use the --tags option to the git push command. This will transfer all of your tags to the remote server that are not already there.
By default, git push only updates the corresponding branch on the remote. So, if you are checked out to the main branch when you execute git push , then only the main branch will be updated. It's always a good idea to use git status to see what branch you are on before pushing to the remote.
If you use git branches a lot, you'll often push each branch after each commit. Instead of pushing every single branch you can do git push --all origin . This will push all commits of all branches to origin.
The message "--all and --tags are incompatible
" comes from builtin/push.c#cmd_push()
This was introduced by Marek Zawirski in commit b259f09 in August 2008 (Git v1.6.1-rc1):
Make push more verbose about illegal combination of options
It may be unclear that
--all
,--mirror
,--tags
and/or explicit refspecs are illegal combinations forgit push
.Git was silently failing in these cases, while we can complaint more properly about it.
In 2008, Marek was implementing git push
in JGit, and proposed that patch mentioned above, adding:
I forgot about this one, it was reported long time ago.
It seems that it may be really unclear what's going on with git failing on
$ git push --tags --all
and similar, as it is implementation related perhaps.
While it is possible to configure a remote with:
[remote "origin"]
push = refs/heads/*
push = refs/tags/*
Jeff King discovered a bug (kind of deadlock) which is probably why this patch exists.
The sender does a "tellme-more" and then waits for a line back.
The receiver gets the tellme-more, but never says anything else, presumably because he doesn't have that commit (because master is ahead of any tags).
In short, pushing branches and tags separately seems easier to support than pushing them together.
See more with "Push git commits & tags simultaneously", with git push --follow-tags
, or git config --global push.followTags true
.
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