Home > Blockchain >  How do I comprehend the 'all' concept in 'git push --all' and simply 'git p
How do I comprehend the 'all' concept in 'git push --all' and simply 'git p

Time:04-26

I am having a bit of a hard time figuring out what the question title suggests. Basically, git push --all(or maybe less often git push --all <remote>) and simply git push but defaulted to 'matching' both give a reference to 'all'.

I did some research over this, but most of what I found was simply the effects of each command respectively, and didn't find anything that has them both in mind. So I was wondering if they have nothing to do with each other at all, or there is indeed overlap and some interplay when they are present together at the same time.

Thanks

CodePudding user response:

Your overall git push command is:

git push [<options>] [<repository> [<refspec> ...]]

That is, there are optional options, such as --all, -n, --tags, and so on. You may use one, or some in combination, or none, as documented. All the options start with - to distinguish them from the remaining arguments.

The remaining arguments are, in order:

  • the repository, then
  • the refspec(s).

If you give no additional arguments (besides options) you have not provided a repository argument, and if you give only one additional argument (besides options) you have supplied a repository but no refspec.

The --all flag is a way of writing the refspec refs/heads/*, without typing in refs/heads/* as a refspec. The fact that you don't have to type it in as a refspec frees you from the obligation to provide a repository. Other than this particular freedom, plus one more constraint, that's all --all means.

(The extra constraint is that if you do use --all you are not allowed to use a refspec.)

Since --all just implies one particular refspec, the rest of the documentation can be read as if you had run:

git push <repository> "refs/heads/*"

for some repository argument. Adding other options such as --dry-run has the effect listed for that option.

[What if] push.defaults [is] configured to be 'matching'?

The push.defaults setting takes effect if you provide no refspec arguments. Since --all effectively does provide a refspec argument, it is ignored if you use --all. If you do not use --all and do not provide a refspec, your push.default setting goes into effect.

  • Related