Reddit user TheGlen made a great post about Gandalf being a fighter not a wizard.
Gandalf lied, he was no wizard. He was clearly a high level fighter that had put points in the Use Magic Device skill allowing him to wield a staff of wizardry. All of his magic spells he cast were low level, easily explained by his ring of spell storing and his staff. For such an epic level wizard he spent more time fighting than he did casting spells. He presented himself as this angelic demigod, when all he was a fighter with carefully crafted PR.
His combat feats were apparent. He has proficiency in the long sword, but he also is a trained dual weapon fighter. To have that level of competency to wield both weapons you are looking at a dexterity of at least 17, coupled with the Monkey Grip feat to be able to fight with a quarter staff one handed in his off hand at that. Three dual weapon fighting feats, monkey grip, and martial weapon proficiency would take up 5 of his 7 feats as a wizard, far too many to be an effective build. That's why when he faced a real wizard like Sarumon, he got stomped in a magic duel. He had taken no feats or skills useful to a wizard. If he had used his sword he would have carved up Sarumon without effort.
The spells he casts are all second level or less. He casts spook on Bilbo to snap him out his ring fetish. When he's trapped on top of Isengard an animal messenger spell gets him help. Going into Moria he uses his staff to cast light. Facing the Balrog all he does is cast armor. Even in the Two Towers his spells are limited. Instead of launching a fireball into the massed Uruk Hai he simply takes 20 on a nature check to see when the sun will crest the hill and times his charge appropriately. Sarumon braced for a magic duel over of the body of Theodin, which Gandalf gets around with a simple knock on the skull. Since Sarumon has got a magic jar cast on Theodin, the wizard takes the full blow as well breaking his concentration. Gandalf stops the Hunters assault on him by parrying two missile weapons, another fighter feat, and then casting another first level spell in heat metal. Return of the King has Gandalf using light against the Nazgul and that is about it. When the trolls, orcs and Easterlings breach the gates of Minos Tiroth does he unload a devastating barrage of spells at the tightly pack foes? No, he charges a troll and kills it with his sword. That is the action of a fighter, not a wizard.
Look at how he handled the Balrog, not with sorcery but with skill. The Balrog approached and Gandalf attempts to intimidate him, clearly a fighter skill. After uses his staff to cast armor, a first level spell, Gandalf then makes a engineering check, another fighter skill, to see that the bridge will not support the Balrog's weight. When the Balrog took a step, the bridge collapsed under its weight. Gandalf was smart enough to know the break point, and positioned himself just far enough back not to go down with the Balrog. The Balrog's whip got lucky with a critical hit knocking Gandalf off balance. The whole falling part was due to a lack of over sight on behalf of the party, seriously how does a ranger forget to bring a rope? Gandalf wasn't saved by divine forces after he hit the bottom, he merely soaked up the damage because he was sitting on 20d10 + constitution bonus worth of hit points.
So why the subterfuge? Because it was the perfect way to lure in his enemies. Everybody knows in a fight to rush the wizard before he can do too much damage. But if the wizard is actually an epic level fighter, the fools rush to their doom. Gandalf, while not a wizard, is extremely intelligent. He knows how his foes would respond. Nobody wants to face a heavily armored dwarf, look at Gimli's problem finding foes to engage in cave troll fight. But an unarmored wizard? That's the target people seek out, before he can use his firepower on you. If the wizard turns out to actually be a high level fighter wearing robes, then he's already in melee when its his turn and can mop the floor with the morons that charged him. So remember fighters, be like Gandalf. Fight smarter, not harder.