"Buy us some bread."
Translation:Купи нам какого-нибудь хлеба.
And why exactly is "какого-нибудь хлеба" all in genitive? Because it all refers to "a portion" of bread? That's where I think I got confused.
какой/ого-нибудь is not the object but an attribute to the object noun хлеб; thus its case must be congruent with хлеб/а similar to an adjective. So the grammatical idea is "buy us [from an unspecified bread quantity]" rather than "buy us whatever [of bread]".
As you say, genitive makes the object an uncountable mass or a whole rather than a countable object among several similar objects.
Купи нам какой-нибудь хлеб = Buy us some kind of bread, for there are several types, but it doesn't matter which one you choose.
Купи нам какого-нибудь хлеба = Buy us some amount of bread, for it doesn't matter how much of that "substance" you buy.
Why not just 'купи нам хлеба'? Is partitive not used like that? What if I am indifferent only to the exact quantity and not the type of the bread? e.g. you always buy me one type of bread at a certain baker, if I say "buy me some bread", I obviously want 'the usual'
The particle "-то" conveys uncertainty. Meaning that neither the speaker nor the listener knows what specific thing is being referred to.
Conversely, the particle "-нибудь" conveys indifference. Meaning that the speaker doesn't really care what specific thing the listener will consequently single out.
This implies that putting a "-то" pronoun into an imperative sentence makes it sound like the speaker doesn't have any idea what they're requesting.
To add: there is a Russian construction contained in "нибудь": ни+imperative verb. Meaning something like "whatever": какой хлеб ни купи, весь невкусный: whatever bread you buy, it's all tasteless. Same goes for где-нибудь (где ни будь, везде хорошо=wherever you are, anywhere is fine), как-нибудь etc.
P.S. I wish someone would write such comments on French and others for complex words and constructions which obviously carry certain logic.