The trait can be hereditary, but the most common way of gaining it is command stars. A general gains the trait when he has 4 stars of command, in all circumstances. Sometimes you'll have a trait that gives 2 stars when commanding infantry or cavalry, and the army will show those if the appropriate unit type is in the army. Those don't count. Traits and retinue that give flat +X command do count.