The idiom is 'to beat a hasty/quick/fast retreat' (no 'for'). It is probably related to military drummers in the past but it is used in all contexts now, without any relevance to the military.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.