git: can't create upstream branch
The problem
I'm going bananas due to this git (or github?) idiosyncrasy - I've created a new branch, but I can't push it to the upstream repo on github. This is not the first branch I'm pushing on this repo, and everything went smooth so far.
Walkthrough
I've created a new branch:
$ git checkout -b adam/no-push-bugfix
Made some changes to a file, and added some of them (this means that some of the changes were not committed):
$ git add --patch path/to/some/file
Made sure the changes are right:
$ git diff --staged
$ git commit -v
$ git status
And tried to push:
$ git push --set-upstream origin adam/no-push-bugfix
$ fatal: adam/whatever-name-bugfix cannot be resolved to branch.
Any idea why is my new branch rejected from upstream?
I could not find the right explanation for this issue on the Internet. So I am adding this to help other people to understand the problem.
Git branch name is case-sensitive and it is mapped to a file/directory in repository (not always but it is common for a new branches). As result case-difference in git branch name may cause a problem like in your case. In this particular case we see that existing branches are started with "Adam/". It means that there is a folder with name "Adam" exists in .git/refs/heads. When you try to push to a branch with name started with "adam/" it conflicts with exiting folder.
TL;DR - checkout the branch again.
Oddly enough, I seem to have been out of the branch somehow. The oh-my-zsh
prompt shows that I'm in the branch, but git branch
shows that I'm not in any branch:
After git checkout Adam/no-push-bugfix
, I seem to be in the branch:
Now everything works well, and I can push the branch to upstream. I'm not sure what's the problem (there's a case difference, for example, between adam
and Adam
).
上一篇: 如何选择性地将单次提交中的某些更改还原为单个文件?
下一篇: git:无法创建上游分支