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."
Swiss rider Fabian Cancellara was second and Belgian rider Greg Van Avermaet was third both 2 minutes, 45 seconds adrift in the chasing pack.
It was a good day for France with Gallopin set to defend the yellow jersey on Monday Bastille Day and for Germany, which later won the World Cup.
Gallopin did enough to erase his deficit of more than three minutes to Nibali and leads him by 1:34.
Portuguese rider Tiago Machado is in third place overall, 4:08 back. But, like Gallopin, he is not considered a Tour contender.
"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."
The last Frenchman to wear the yellow jersey was Thomas Voeckler in 2011. He also wore it in 2004 the year disgraced cyclist Lance Armstrong won the sixth of seven Tour wins, before later being stripped of all of his titles for doping.
"It was always a dream of wearing the yellow jersey. But there's a difference between dreams and reality," Gallopin said. "I think I'll have trouble sleeping, but I will have to rest properly to be ready for the battle tomorrow."
Tour de France
P Monday, 5 a.m.
TV • NBCSN