Los Blancos dropped their first league points of the campaign against Osasuna last weekend, which allowed Barcelona to move to the top of the division.
Carlo Ancelotti's side have opened up a three-point advantage on their Clasico rivals, though, courtesy of a narrow success at Coliseum Alfonso Perez.
Militao's header came in the third minute of the contest, with the Brazilian meeting a delivery from Luka Modric, who was back in the starting XI after recovering from injury.
Getafe came close to levelling in the 22nd minute through Fabrizio Angileri, but his effort, which came after smart work from Carles Alena, just missed the post.
Real Madrid were awarded a penalty in the first period when Vinicius Junior was fouled by Luis Milla, but the decision was ultimately overturned, as the ball had gone out of play before the spot kick was given.
Los Blancos had chances to score early in the second period, with Rodrygo and Aurelien Tchouameni coming close, before Domingos Duarte just missed the target down the other end.
Rodrygo had the ball in the back of the home side's net just before the hour, but it was chalked off, with the forward clearly offside.
One goal was enough for Real Madrid to triumph, though, with Ancelotti's side top of the table on 22 points, while Getafe sit down in 16th with just seven points to show from their eight matches this term.