Fixing “The upstream branch of your current branch does not match” in Git
When git push stops with fatal: The upstream branch of your current branch does not match, the upstream of the current branch is a remote branch with a different name. If you want to push to a branch with the same name, run git push -u origin HEAD to change the upstream. After that, git push alone is enough.
This error appears when you create a work branch from the remote main, for example with git switch -c feature/login origin/main, and then push. I reproduced the error, read the full message, and tested the fix for each destination, plus a setting that prevents the error from happening in the first place.
I tested on Ubuntu 24.04 with Git 2.43.0 and bash 5.2. The remote was a bare repository created in the same environment. I ran commands with LANG=C so the messages are in English. I did not change push.default or branch.autoSetupMerge (I kept the defaults). In the output, I replaced the remote path with /path/to/…. I did not test pushing to hosting services such as GitHub, and I did not test on Windows or macOS.
Pushing a branch created from origin/main stops
I created feature/login from origin/main. When it was created, the message set up to track 'origin/main' appeared, so the upstream was origin/main from the start.
$ git switch -c feature/login origin/main
Switched to a new branch 'feature/login'
branch 'feature/login' set up to track 'origin/main'.
$ git branch -vv
* feature/login f39804d [origin/main] 最初のコミット
main f39804d [origin/main] 最初のコミット
The part in [ ] in the git branch -vv output is the upstream of each branch. I added one commit in this state and ran git push without arguments. It stopped with the following message. The exit code was 128, and nothing was sent to the remote.
$ 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 choose either option permanently, see push.default in 'git help config'.
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'.
On the other hand, git pull did not stop. It only fetches from the upstream origin/main, and it printed Already up to date.
Why a name mismatch stops the push
What a plain git push sends, and where, is determined by the push.default setting. According to the git config reference, the default since Git 2.0 is simple. With simple, the current branch is pushed to the remote branch with the same name. If you push to the same remote that pull uses, the upstream must also have the same name.
The Git source (builtin/push.c) also shows that with simple, if the upstream name differs from the current branch name, Git stops with this error. The message gives two options: push to the upstream main, or push to a branch with the same name. Specifying the destination on the command line lets the push succeed.
The upstream became origin/main because of another setting, branch.autoSetupMerge. According to the reference, its default is true. When you create a branch from a remote branch such as origin/main, that starting point becomes the upstream, even if the names differ.

To push to a branch with the same name, use git push -u origin HEAD
Use this fix when you want the work branch to be pushed as origin/feature/login. I ran git push origin HEAD, which is the second option in the message, and feature/login was created on the remote. The git push reference says git push origin HEAD pushes the current branch to the remote branch with the same name.
However, the upstream was still origin/main. When I ran a plain git push again, it stopped with the same error.
$ git push origin HEAD
To /path/to/remote.git
* [new branch] HEAD -> feature/login
$ git branch -vv
* feature/login 1f1a799 [origin/main: ahead 1] ログイン画面
main f39804d [origin/main] 最初のコミット
$ git push
fatal: The upstream branch of your current branch does not match
(以下、上と同じメッセージなので省略)
If you add -u (--set-upstream) to the push, the pushed branch becomes the upstream. The output included set up to track 'origin/feature/login', and the upstream changed.
$ git push -u origin HEAD
To /path/to/remote.git
1f1a799..101272e HEAD -> feature/login
branch 'feature/login' set up to track 'origin/feature/login'.
$ git branch -vv
* feature/login 101272e [origin/feature/login] ログイン画面2
main f39804d [origin/main] 最初のコミット
After I added another commit, a plain git push succeeded without an error.
$ git push
To /path/to/remote.git
101272e..a225f71 feature/login -> feature/login
$ git status -sb
## feature/login...origin/feature/login
Removing the upstream before pushing also fixed the problem. For feature/search, which I also created from origin/main, I ran git branch --unset-upstream to remove the upstream. The message then changed to has no upstream branch, which shows there is no upstream. Next, I set push.autoSetupRemote to true and ran git push. This created a branch with the same name and made it the upstream. For the error when there is no upstream and for push.autoSetupRemote, see the separate article "How to set the upstream branch in Git."
$ git branch --unset-upstream
$ git push
fatal: The current branch feature/search has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin feature/search
To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.
$ git -c push.autoSetupRemote=true push
To /path/to/remote.git
* [new branch] feature/search -> feature/search
branch 'feature/search' set up to track 'origin/feature/search'.
To push to upstream main, use git push origin HEAD:main
When you really want to push the commit on the work branch to the remote main, write the destination as HEAD:main, which is the first option in the message. I tested this on the hotfix branch, whose upstream is origin/main, and the remote main advanced. The upstream stays origin/main, so you also need to add HEAD:main the next time you push.
$ git branch -vv
feature/login a225f71 [origin/feature/login] ログイン画面3
* hotfix 0d9a389 [origin/main: ahead 1] 修正
main f39804d [origin/main] 最初のコミット
$ git push origin HEAD:main
To /path/to/remote.git
f39804d..0d9a389 HEAD -> main
If you set push.default to upstream, a plain git push sends to the upstream branch, which is main in this case. I added a commit to hotfix2, which was also created from origin/main. Then I tried the setting only once with -c, and it pushed hotfix2 -> main.
$ git -c push.default=upstream push
To /path/to/remote.git
0d9a389..5dcfa2c hotfix2 -> main
If you set push.default to upstream, every git push from a branch created from origin/main sends to the remote main. Before you change this setting, check what each branch's upstream is with git branch -vv. That way you won't advance main by accident when you meant to push a work branch.
Stop setting an upstream automatically
Setting branch.autoSetupMerge to simple, which the message suggests, sets an upstream only when the starting remote branch has the same name. This follows the reference. After I set it, I created feature/profile from origin/main. The set up to track line did not appear, and git branch -vv showed no upstream.
$ git config branch.autoSetupMerge simple
$ git switch -c feature/profile origin/main
Switched to a new branch 'feature/profile'
$ git branch -vv
(ほかのブランチは省略)
* feature/profile 5dcfa2c 修正2
If you want to avoid setting an upstream only for one branch and keep the configuration unchanged, add --no-track to git switch. This also did not set an upstream.
A plain git push on a branch without an upstream stops with has no upstream branch. I added a commit to feature/cart and ran git push -u origin HEAD. This made origin/feature/cart, with the same name, the upstream. Because no mismatched upstream was set, does not match did not appear.
$ git switch -c feature/cart --no-track origin/main
Switched to a new branch 'feature/cart'
$ git branch -vv
* feature/cart 5dcfa2c 修正2
(ほかのブランチは省略)
(ここで feature/cart にコミットを1つ足した)
$ git push
fatal: The current branch feature/cart has no upstream branch.
(以下、案内の行は省略)
$ git push -u origin HEAD
To /path/to/remote.git
* [new branch] HEAD -> feature/cart
branch 'feature/cart' set up to track 'origin/feature/cart'.
$ git branch -vv
* feature/cart 893cb4b [origin/feature/cart] カート
(ほかのブランチは省略)





