Amelio Vazquez-Reina
Amelio Vazquez-Reina

Reputation: 96468

git config: "remote.origin.push" vs "push.default"

How does the following command:

git config remote.origin.push refs/heads/master:refs/heads/master

relate to the following command:

git config push.default <option>

(either with the --local or --global option)

where <option> is one of:

nothing
matching
upstream (formerly tracking)
current
simple

?

I think I understand the second config command, but I don't understand how the first command conditions/relates to the second. Here are some references that provide context behind this question:

Upvotes: 5

Views: 6982

Answers (1)

torek
torek

Reputation: 490078

When you run:

git push origin ...

whatever is set in remote.origin.push overrides whatever is set in push.default. More generally, if remote.name.push is not set (here name is origin), git falls back on push.default, and then if that is also not set, it falls back on the built-in defaults as described in your links.

(Edit: as noted in Breaking Benjamin's comment below and my reply to it, if there is a ... part that contains at least one refspec, the refspec overrides remote.origin.push. So remote.origin.push applies only when you name origin explicitly or implicitly on the command line and omit any and all refspecs on the command line as well. For example, git push with no arguments that discovers origin, or git push origin with no additional arguments, has Git look up your remote.origin.push setting and use it; but git push origin xyz does not use your remote.origin.push setting. Of course the ... part above can include more flags, so the correct question at this point is whether the ... part contains any refspecs.)

Note that:

git config --local na.me value

means the same thing as without --local. When setting values (as here) the --local, --global, and --file filename options control where the value is set, but --local is the default.

(When fetching values:

git config na.me

[or git config --get or git config --get-all or git config --get-regexp], the --local, etc, options restrict where git will read from, and without one it reads from all of them, with the "most local" overriding a "less local" if something is set in more than one place.)

Upvotes: 8

Related Questions