fatal: The upstream branch of your current branch does not match the name of your current branch

回眸只為那壹抹淺笑 提交于 2019-11-28 16:58:22

For the benefit of the readers who might miss the probably most important detail, well hidden in the comments:

This is due to the git config push.default setting. It defines what git does when you enter git push (see link).

In the question, apparently the setting was set to simple (which is the default for git v2), probably with

git config --global push.default simple

This means, that git refuses to push when the local and remote branch do not match exactly.

As @TomSpurling notes, above setting is safer and recommended for normal use, because usually you want the same names for your local and remote branches.

However in certain situations, when your local branch is tracking some different remote branch with a different name, then you want to change that:

To allow to push to the tracking branch on a per-git basis, thus make git pull and git push symmetric, use

git config push.default upstream

Note: To globally set this for all of your gits, use git config --global push.default upstream
However it is probably better to leave it to git config --global push.default simple and only set this option in those workloads, where it is really required.

Your local branch is called rel_5.4.1 but the remote branch is releases/rel_5.4.1 (as far as Git is concerned, the / has no special meaning in branch names except to make them easier to read for the human eye).

When you push, Git is wary whether you want to push your branch to releases/rel_5.4.1 (the name of the remote branch) or whether you want to create a new remote branch. It does notice the similarity of names, though.

Unless you want to create a new branch, the correct command is

git push origin HEAD:releases/rel_5.4.1

You could also use

git push origin rel_5.4.1:releases/rel_5.4.1

To fix the warning once and for all, rename your local branch to match the remote name:

git branch -m releases/rel_5.4.1

This error can be fixed for once and all, with:

git branch releases/rel_5.4.1 -u origin/releases/rel_5.4.1

It changes the upstream of the branch, to match the correct remote (again).

In my case git branch --unset-upstream solved that issue.

Seems like having a local branch name which is different than the remote is not what Git likes too much. You will need to issue:

git push origin HEAD:releases/rel_5.4.1

explicitely on every push

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!