fatal: The upstream branch of your current branch does not match the name of your
current branch. comes from a plain git push when your branch tracks a
remote branch with a different name and push.default is simple.
Push to a branch of your own name with git push -u origin HEAD, which also
moves the tracking to it.
If you really meant to push into the other branch, name it:
git push origin HEAD:main. Git prints both commands in the message itself.
The error
> git status -sb
## feature/login...origin/main [ahead 1]
> git push
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use
git push origin HEAD:main
To push to the branch of the same name on the remote, use
git push origin HEAD
To avoid automatically configuring an upstream branch when its name
won't match the local branch, see option 'simple' of branch.autoSetupMerge
in 'git help config'.
exit=128
The empty lines in this block were printed by PowerShell 5.1 as
System.Management.Automation.RemoteException; they are shown here as the empty
lines Git wrote.
Why it happens
The branch was created with git switch -c feature/login --track origin/main,
so its upstream is origin/main, as git status -sb shows. With
push.default set to simple in the repository's config, a bare
git push refused to push feature/login into a remote branch with
another name and stopped with exit code 128. Branching from a remote branch with
--track, or from a tool that sets tracking for you, gives this setup.
The fix
> git push -u origin HEAD
branch 'feature/login' set up to track 'origin/feature/login'.
To C:/.../up/remote.git
* [new branch] HEAD -> feature/login
exit=0
> git status -sb
## feature/login...origin/feature/login
> git push
Everything up-to-date
exit=0
git push -u origin HEAD created feature/login on the remote and
changed the upstream to it, so the next plain git push answered
Everything up-to-date. The remote path is shortened; nothing else in the
block changed. The alternative, git push origin HEAD:main, pushes your commit
into main on the remote; use it only when that is what you want, and it was
not run in this test.
How it was reproduced
Git for Windows 2.45.2.windows.1 in Windows PowerShell 5.1: a local bare repository as the
remote, a clone with one commit pushed to main, then
git switch -q -c feature/login --track origin/main, one commit, and
git config --local push.default simple (repository config only). A bare
git push gave the error; git push -u origin HEAD fixed it.
Frequently asked
- How do I fix upstream branch does not match the name of your current branch?
- Run git push -u origin HEAD. It pushes your branch under its own name and sets that as the new upstream, so later plain git push commands work.
- Why does my branch track origin/main?
- In this test the branch was created with git switch -c feature/login --track origin/main, which sets origin/main as its upstream. git status -sb shows the upstream after the three dots.
- How do I push my branch into main on the remote instead?
- Name the target: git push origin HEAD:main. Git prints this command in the error message as the way to push to the upstream branch.
A related message for a branch with no upstream at all is The current branch has no upstream branch. More decoded errors in the Fixes category.