Skip to content

Instantly share code, notes, and snippets.

@ParadoxV5
Created October 15, 2025 04:26
Show Gist options
  • Save ParadoxV5/61405e1a7de9a8371c9410bb344e8674 to your computer and use it in GitHub Desktop.
Save ParadoxV5/61405e1a7de9a8371c9410bb344e8674 to your computer and use it in GitHub Desktop.
`git push` defaults

git push defaults

Here, I will call the currently-checked-out (HEAD) local branch as simply the current branch.

The Default Repository

If the repo is omitted, git push searches the following configs and uses the first one configured:

  1. branch.<current branch>.pushRemote
  2. remote.pushDefault
  3. branch.<current branch>.remote

The Default Refspec

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).

push.default options

nothing

  • Just error and push nothing

By preventing remote guessing, this is the most pessimistic option for preventing accidental pushes to incorrectly guessed remotes.

upstream and (deprecated) tracking

  • 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-to helps with configuring these configs with the right contents.
  • git push --set-upstream or simply git push -u automatically sets them after the push succeeds.
    • This is default on if push.autoSetupRemote is configured to true.
  • 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.

current

  • Push the current branch to the same-named remote branch
  • The default remote repo is origin.

simple (default)

  • Similar to current
  • If push.autoSetupRemote is 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>.
  • Error if the upstream is configured differently

This is defaulted for beginners as it is pessimistic enough without beïng overly inconvenient.

matching

  • Do current to --all branches

This is the default until Git 2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment