The 29-year-old German, a three-time world time trial champion, broke away with specialist climber Alessandro De Marchi of Italy.
"The objective was to win the stage. There was a chance to do it and I felt good, my legs felt good," Martin said. "I knew it would be one of my rare chances to win a stage."
The 170-kilometer (105.4-mile) trek from Gerardmer to Mulhouse — in the mid-sized Vosges mountain range near the German border — featured six mostly moderate uphill treks that posed Martin little problem, even though he is not a reputed climber.
"When the stage started to climb I realized I was stronger and started to attack and then things went well," he said. "We're close to Germany and that was an extra incentive."
It was a good day for France with Gallopin set to defend the yellow jersey on Monday —
Martin plans to have his feet up in front of the television.
"Of course I will watch it," said Martin, who clocked a winning time of 4 hours, 10 minutes. "Let's say Germany will win — that's for sure. I'm a good omen. Let's say 3-0."
Gallopin, of the Lotto Belisol team, finished several minutes behind but did well enough to erase his deficit of more than three minutes to Nibali.
"It's with great pride that I will ride on the national holiday day in the yellow jersey," the 26-year-old Gallopin said. "It's a little bit scary, but I will enjoy the day."
Gallopin leads Nibali by 1 minute, 34 seconds.
The last Frenchman to wear the yellow jersey was
Shortly before the day's most difficult climb — a Category 1 ascent of 10.8 kilometers up Le Markstein — Martin broke away about 60 kilometers from the end. Gallopin's chasing group was about two minutes behind them and Nibali more than six minutes adrift.
Martin was no threat to Nibali's yellow jersey, but the 26-year-old Gallopin was.
Nibali was losing more and more ground, and urged his Astana teammates to step up the pace as they reached the last of climbs — a short, but sharp climb up Grand Ballon. But they had left themselves far too much to do.