After doing a checkout of the remote branch releases/rel_5.4.1
using the Git GUI, I'm seeing this unexpected error message when I try to 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:releases/rel_5.4.1
To push to the branch of the same name on the remote, use
git push origin rel_5.4.1
I don't know what Git is talking about. I probably want to push to origin releases/rel_5.4.1
since that's the branch which I checked out. So neither option seems correct to me.
git status
says I'm on branch rel_5.4.1
.
Here is the branch as it appears in my .git/config
:
[branch "rel_5.4.1"]
remote = origin
merge = refs/heads/releases/rel_5.4.1
What is going on?
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 whatgit
does when you entergit push
(see link).In the question, apparently the setting was set to
simple
(which is the default forgit v2
), probably withThis means, that
git
refuses to push when the local and remote branch do not match exactly. To allow to push to the tracking branch, thus makegit pull
andgit push
symmetric, useNote: Leave
--global
away to just change the setting for the current (local)git
repository.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:explicitely on every push
In my case
git branch --unset-upstream
solved that issue.Your local branch is called
rel_5.4.1
but the remote branch isreleases/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
You could also use
To fix the warning once and for all, rename your local branch to match the remote name:
This error can be fixed for once and all, with:
It changes the upstream of the branch, to match the correct remote (again).