Here, I will call the currently-checked-out (HEAD) local branch as simply the current branch.
If the repo is omitted, git push searches the following configs and uses the first one configured:
branch.<current branch>.pushRemoteremote.pushDefaultbranch.<current branch>.remote
If the refspec (local & remote branches) is omitted, the default is the remote.<repo>.push config.
If only one branch is specified, it is the name of both the local and the remote branches.
But if the entire remote.<repo>.push is also missing, then the push.default config determines the default branches (and repo if omitted too).
- Just error and push nothing
By preventing remote guessing, this is the most pessimistic option for preventing accidental pushes to incorrectly guessed remotes.
- Push the current branch to the upstream branch, whatever it is
- Errors if a repo is specified but different from the upstream.
The upstream is the remote branch where you pull from.
It is separately configured at branch.<current branch>.remote for the remote and branch.<current branch>.merge for the branch.
git branch --set-upstream-tohelps with configuring these configs with the right contents.git push --set-upstreamor simplygit push -uautomatically sets them after the push succeeds.- This is default on if
push.autoSetupRemoteis configured to true.
- This is default on if
- Once configured,
@{upstream}or simply@{u}points to it.
While it is usually the remote branch you push to, it can be different in some cases; for example:
- You might pull straight from a base branch, but then push to a separate branch to create a merge with.
- As a non-member of a GitHub repo, you must fork it to contribute through a PR. While you can only push to your fork, you can skip tracking the base repo with separate “base” branch(es) by pulling from it instead.
- Push the current branch to the same-named remote branch
- The default remote repo is
origin.
- Similar to
current - If
push.autoSetupRemoteis not true, error if the upstream is not configured- This is why first-time pushes error and suggest
git push --set-upstream origin <current branch>.
- This is why first-time pushes error and suggest
- Error if the upstream is configured differently
This is defaulted for beginners as it is pessimistic enough without beïng overly inconvenient.
- Do
currentto--allbranches
This is the default until Git 2.0.