QM/QMG (quartermaster/quartermaster general) was the title originally given to the officer entrusted with providing armies with accommodation (quarters) as well as food and equipment. It became a prefix to some NCO ranks (thus company QM sergeant, etc.) to denote their particular responsibility with regard to supply.
In most countries, particularly in Prussia and Austria, the entire concept of a general staff grew up around the office of the QMG, in recognition of the fact that warfare is, above all, a matter of logistics. At an early stage, again in most armies, other specialist functions such as engineering and intelligence tended to gravitate to the department. The pressure of campaigning meant that, for example, the Indian army QMG was well ahead of its English equivalent in performing the tasks of a general staff. During WW I Ludendorff took the title ‘1st QMG’, a fitting title for a post which gave him extraordinary political as well as military power, although Hindenburg, as CGS, was senior.
At the regimental level the role of QM (S4 in the US system) is invested with a great deal of responsibility, and is usually given to an officer with a proven record of reliability and strong organizational skills. Traditionally the British army gives the post of regimental QM to an officer commissioned from the ranks. The QMG remains among the top ranks of most armies.
— Andrew Haughton/Richard Holmes