What does Git push do without a branch name?

Understand push.default, remote selection, upstream tracking, and explicit refspecs before relying on a bare git push.

Best practices
Illustration of Git history and collaboration

When you run git push without a branch name, Git must choose both a destination remote and the references to update. In an ordinary single-remote setup with no explicit push refspec configured, push.default controls the branch selection. Its default has been simple since Git 2.0.

In a central workflow, simple pushes the current branch to its same-named upstream branch. A missing upstream or a mismatched upstream name normally produces an error. Configuration can change this behavior, so inspect it before assuming a bare push has a particular destination.

Understand the branch-selection modes

push.default What a default push requests
simple Push the current branch to the same name; in a central workflow, check that its upstream has that name
current Push the current branch to the same name on the selected remote, creating that branch if permitted
upstream Push to the configured upstream branch, which may have another name; intended for a central workflow
matching Push every local branch that has a same-named branch on the selected remote
nothing Reject a push without an explicit refspec

matching remains a supported mode. It stopped being the default in Git 2.0; it was not removed. It can send more branches than you intended, but it does not by itself force non-fast-forward updates or bypass server protections.

Inspect the effective settings:

git config --show-origin --get push.default
git config --show-origin --get push.autoSetupRemote
git branch -vv
git remote -v

An unset configuration key produces no value and a nonzero exit status. For push.default, an unset value means Git uses its built-in default.

Separate remote selection from branch selection

Branch-specific pushRemote, remote.pushDefault, and the branch's configured remote can affect where a bare push goes. An explicit command-line refspec or configured remote.REMOTE.push takes precedence over push.default for what to push.

In a triangular workflow, you might fetch from one remote and push to another. simple then behaves like current for the different push destination; the same-upstream-name check from the central workflow does not describe every setup.

Another exception is push.autoSetupRemote=true: with simple, current, or upstream, it can establish upstream tracking during a default push when none exists. See the Git configuration reference.

Make the first push explicit

After checking the remote URL and branch name:

git push --dry-run origin feature-x
git push -u origin feature-x

Replace feature-x with the local branch you intend to publish. The dry run previews the requested update; the second command performs it and sets tracking for a successful or already up-to-date branch. Tracking also helps git pull and ahead/behind reporting, though later configuration changes can still alter push behavior.

To publish under a different remote branch name:

git push origin local-name:remote-name

The left side selects the local source; the right side names the remote destination. This explicit refspec avoids relying on the current branch-selection mode. See git-push.

FAQ

How do I fix “The current branch has no upstream branch”?

Verify the destination, then use git push --set-upstream origin BRANCH if that is where the branch belongs. Do not copy a suggested remote blindly when the repository uses separate fetch and push destinations.

Can I change the default for just this repository?

Yes. For example, git config --local push.default current selects same-named remote branches for default pushes in this repository. Use --global only when you want the setting across your repositories. Explicit refspecs and remote push configuration can still take precedence.

Does matching overwrite other people's work?

It may attempt updates to several matching branches, which increases the chance of publishing unintended work. Normal fast-forward checks still apply. Force options are a separate choice and are not enabled merely by selecting matching.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting