Branching is determined by a complex interplay between genetics and the environment. The plant is genetically programmed to produce periodic nodes along its stem as it grows upward. In most plants, these are spaced according to a specific pattern encoded in the DNA.
These nodes are potential branches, but not all of them will necessarily develop, and here is where the environment plays a role. Growth requires precious energy, and the hormonal system of the plant will adjust to environmental factors to allocate that growth energy in a way that will maximize its future ability to gather light.
If there is not much light in the environment, the tip of the plant’s stem releases a hormone called auxin which inhibits the growth of the branch buds further down on the stem. This causes the plant’s growth to be concentrated up at the top of the stem, so that it goes upward instead of branching out laterally. This sustained upward growth may allow the plant to reach up above whatever has been shading it.
If there is an abundance of light in the environment, there’s plenty of energy to apply to growth in all directions. In this case, less auxin is produced by the tip so that more branches can deploy out laterally to grab that light.
Also, if the tip is damaged (as often occurs) it can no longer produce auxin, so the buds further down the stem are no longer inhibited and will be prompted to grow. This is why pruning shrubs encourages bushier growth.