jaffa
jaffa

Reputation: 27360

What is the significance of missing parameters on the 'git push' command?

What is the significance of the following commands:

  1. git push
  2. git push origin
  3. git push origin master

Upvotes: 3

Views: 1368

Answers (1)

CB Bailey
CB Bailey

Reputation: 792647

git push <remote> <refspec>

This command pushes some things from the local repository to a remote repository. <remote> can be the name of a configured remote or a full URL to a remote git repository.

<refspec>, in its general form is an optional + followed by <src>:<dst> where <src> is the name of a local branch, tag or commit id and <dst> is the name of a remote branch or tag to push to. If :<dst> is omitted, it is equivalent to <src>:<src>. This means that git push origin master is equivalent to git push origin master:master. The + is used to attempt non fast-forward pushes.

If you don't supply a remote repository (third parameter), then the configured remote for the current branch (if any) will be used, or origin if none.

If you don't supply a refspec to push (the fourth parameter) then if there is a configured push refspec for the remote being pushed (config variable: remote.<remotename>.push) then that is used, otherwise the behaviour depends on the setting of the config variable push.default.

The default is matching which pushes all local branches which match (by name) a remote branch on the remote being pushed to.

Other options for push.default are nothing (which does nothing), upstream or tracking which pushes the current branch to its configured upstream branch and current which pushes the current branch to an identically named branch on the remote.

Upvotes: 5

Related Questions