It is interesting to look at FM 27-10, The Law of Land Warfare (which is primarily a 1956 effort, except in some areas not relevant here, representing the post-WWII experience with Germany, Japan and transitions where a friendly government is on deck):

Section II. ADMINISTRATION OF OCCUPIED TERRITORY

362. Necessity for Military Government

Military government is the form of administration by which an occupying power exercises governmental authority over occupied territory. The necessity for such government arises from the failure or inability of the legitimate government to exercise its functions on account of the military occupation, or the undesirability of allowing it to do so. (See par. 12, which discusses military government, and par. 354, dealing with civil affairs administration.)

363. Duty to Restore and Maintain Public Order

The authority of the legitimate power having in fact passed into the hands of the occupant, the latter shall take all the measures in his power to restore, and ensure, as far as possible, public order and safety, while respecting, unless absolutely prevented, the laws in force in the country. (HR, art. 43.)
which are the default for a legal occupation. The transition to civil affarirs adminitration is covered here:

354. Friendly Territory Subject to Civil Affairs Administration Distinguished

Civil affairs administration is that form of administration established in friendly territory whereby a foreign government pursuant to an agreement, expressed or implied, with the government of the area concerned, may exercise certain authority normally the function of the local government.

Such administration is often established in areas which are freed from enemy occupation. It is normally required when the government of the area concerned is unable or unwilling to assume full responsibility for its administration. Territory subject to civil affairs administration is not considered to be occupied.

If circumstances have precluded the conclusion of a civil affairs agreement with the lawful government of allied territory recovered from enemy occupation or of other territory liberated from the enemy, military government may be established in the area as a provisional and interim measure (see par. 12 b and c). A civil affairs agreement should, however, be concluded with the lawful government at the earliest possible opportunity.
A neat simple outline of legal responsibilities. As you say, "nation building" is another manual.

Regards

Mike