0

I recently started learning git and I've run into a behavior I don't quite understand.

I have two branches:

C:\Users\MyUserName\MyProject>git branch

* MyBranch
  master

git makes it very clear that there are two branches and that MyBranch is currently selected by highlighting it in green and putting an asterisk next to it.

Switching to the main branch looks like this:

C:\Users\MyUserName\MyProject>git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.


C:\Users\MyUserName\MyProject>git branch
  MyBranch
* master

All of this is fine until I do this:

C:\Users\MyUserName\MyProject>git checkout mybranch
Switched to branch 'mybrach'


C:\Users\MyUserName\MyProject>git branch
  MyBranch
  master

None of my branches are currently highlighted as selected, no errors were thrown at me for checking into a branch that doesn't exist and neither was a lowercase copy of MyBranch created. However, git apparently completed the selection successfully as it states "Switched to branch 'mybranch' "

I figured this was specifically a case-sensitivity issue very quickly since trying to checkout to a branch name that doesn't exist would throw an error:

C:\Users\MyUserName\MyProject>git checkout random
error: pathspec 'random' did not match any file(s) known to git

What's happening here? Does git actually make the switch but chooses not to highlight or no switch happens but git still displays a "switched" message?

nms1s
  • 1
  • 1
  • A branch is nothing more than a file with an ID of a commit inside it. This is probably something where git is case-sensitive and windows is not? Or maybe it's the other way round. – evolutionxbox Jan 20 '21 at 22:11
  • Not really, my question is, if let's say git IS case sensitive, then why doesn't it raise an error the same way it does if the branch name you entered doesn't exist? It says 'switched to branch' but when you check current local branches none of the existing ones are selected. – nms1s Jan 20 '21 at 22:17
  • @evolutionxbox: ... except when the branch name is stored in some *other* form (rather than as a case-insensitive file), such as in `.git/packed-refs`. This is where the mess comes in. Git itself is case-sensitive in branch names, but when Git uses a case-insensitive file system, everything gets confusing and confused. Best not to do this sort of thing, at least until Git stops using file names to hold branch names (there's a slow but ongoing project for that). – torek Jan 20 '21 at 22:17
  • @nms1s: see [my answer](https://stackoverflow.com/a/38494084/1256452) to the linked question. – torek Jan 20 '21 at 22:18
  • @torek good point. – evolutionxbox Jan 20 '21 at 22:27
  • @evolutionxbox thank you! – nms1s Jan 20 '21 at 22:31
  • @nms1s you should thank torek. He is full of git knowledge – evolutionxbox Jan 20 '21 at 22:32
  • @torek thank you too sir – nms1s Jan 21 '21 at 17:04

0 Answers0