2

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?

Community
  • 1
  • 1
Adam Matan
  • 128,757
  • 147
  • 397
  • 562

2 Answers2

6

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.

Alex Konshin
  • 79
  • 1
  • 2
2

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:

enter image description here

After git checkout Adam/no-push-bugfix, I seem to be in the branch:

enter image description here

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).

Adam Matan
  • 128,757
  • 147
  • 397
  • 562