When in a building you can tell the MG to get out and move to a particular spot, rather than tell the building that everyone inside needs to get out. Doing that should help.
Yeah, don't just mash down on the "Exit" button (or de-garrison or whatever it is). Pretty sure you need to click the building, click the icon of the MG, then either press "D" or click the Exit button, then click where you want the MG to go. That will stop it from setting up in some nonsense direction the moment it steps outside. If you tell the MG to exit to a certain point (the cursor will change to an open-top rectangle), you can select it while it is en route to the new location and give it a retreat order.
It is usually a panic move and reliant on muscle memory, so that may be totally the wrong order of button presses, but hopefully it will help to know that it IS possible!