You heard correctly that the Holy Prophet Muhammad (may peace and blessings of Allah be upon him) shaved off his head only on the occasions of Hajj and Umrah. Generally, the Holy Prophet Muhammad (may peace and blessings of Allah be upon him) and the Companions (may Allah be pleased with them) used to grow hair on their head. It is also proved that some Companions would shave off their head as well. The correct opinion is that it is habitual sunnah, so it is lawful if someone shaves off his head in occasions other than Hajj and Umrah. However it is more adequate and better to grow it, one shall earn reward if he grows hair as per the sunnah of the Holy Prophet Muhammad (may peace and blessings of Allah be upon him). Mulla Ali Qari (may Allah have mercy upon him) writes:
“(احلقوا كله او اتركوه كله)” فيه إشارة إلى الحلق فى غير الحج والعمرة جائز وان الرجل مخير بين الحلق والترك لكن الأفضل أن لا يحلق إلا فى أحد النسكين كما كان عليه صلى الله عليه وسلم مع أصحابه رضى الله عنهم ، وانفرد منهم علي كرم الله وجهه (مرقات ج 4 ص 4098 بمبئى)
Allah knows Best!
Darul Uloom Deoband