Have Git set an upstream on the first push
Configure push.autoSetupRemote, distinguish publishing from branch-creation tracking, and troubleshoot cases where automatic setup does not apply.
With Git 2.37 or later, enable automatic upstream setup for default pushes:
git config --global push.autoSetupRemote true
When the current branch has no upstream, this makes a supported default push behave as though --set-upstream were supplied. It applies with push.default set to simple, upstream, or current.
Push a new branch
git switch -c feature-x
# Make and commit changes as needed.
git push
The selected remote receives the same-named branch and Git records tracking after a successful push. The destination is determined by your branch and remote configuration; it is not necessarily origin. A suitable remote and write access must already exist.
Omit --global when you want the setting only in the current repository. The option does not change an upstream that already exists.
Understand the older alternatives
git config --global push.default current
current pushes the current branch to the same name on the selected remote, but alone it does not establish an upstream. An explicit first push remains available:
git push -u origin HEAD
branch.autoSetupMerge addresses a different moment: creating a branch from an existing starting point. Setting it to always can make a feature branch track a local branch such as main; that is not equivalent to setting up tracking when publishing it.
| Setting | Purpose |
|---|---|
push.autoSetupRemote |
Add tracking during a qualifying first default push |
push.default current |
Choose the current branch and same destination name |
branch.autoSetupMerge |
Choose tracking when a branch is created |
Troubleshoot the configuration
git --version
git config --show-origin --get push.autoSetupRemote
git config --show-origin --get push.default
git branch -vv
git remote -v
Git accepts unknown configuration names, so setting the option on an older version is not proof that it supports the behavior. Repository configuration can override a global value.
A default push may name a remote, such as git push origin, while omitting refspecs. Explicit refspecs, such as git push origin feature-x, do not use this automatic default-push setup; add -u when you want tracking in that case. A configured remote.<name>.push can also supply refspecs and affect the path taken.
Use different local and remote names
Specify the mapping and tracking explicitly:
git push -u origin local-name:remote-name
With the default simple policy, later plain pushes can refuse mismatched upstream names. Continue using an explicit mapping or select a policy that matches your workflow.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan