Seen from Gandalf's side, the War of the Ring was improvised misdirection that still worked.
He was sent with the other Istari around the year 1000 of the Third Age, specifically to support the free peoples of Middle-earth against Sauron. When he arrived, no one knew where Sauron or the Ring were, or when the next confrontation would come. Unlike the others, he never settled anywhere, roaming the Westerlands instead.
He eventually figured out that the mysterious necromancer in southern Mirkwood was Sauron, and persuaded the White Council, really Saruman, that they should attack him there. Sauron escaped down to Mordor rather than being destroyed, and from that point the countdown to the final confrontation had started.
He traced the ring's history from Isildur forwards and from Bilbo backwards, and with Aragorn hunted and captured Gollum. He then scoured the ancient records of Minas Tirith and found Isildur's note that when hot the ring showed the letters of the ring rhyme. He rushed to the Shire, tested it, and it was true.
He thought Rivendell the best and safest place for it in the immediate term, and valued Elrond's wisdom in deciding what to do with it. Ironically, that was where Isildur was heading when he was ambushed. The ring completed that journey three thousand years later, via the Anduin, the Misty Mountains, the Lonely Mountain and the Shire.
Saruman was head of his order and very knowledgeable, and Gandalf did not yet know he had turned. Going meant abandoning his information gathering, and Isengard lay too far south for him to return in time for Frodo. He asked Radagast to send news there and wrote Frodo a letter, which Barleyman forgot to pass on.
Saruman kept him prisoner there for two months before Gwaihir rescued him. The visit confirmed his fears that Saruman was no longer on their side, that he was building an army, and that Sauron was on the move again. By then Frodo should already have set off, with Black Riders hunting for the Shire.
Gwaihir could not fly him there, so Gandalf asked to be dropped at Edoras, a little way in the wrong direction, because Rohan had the best horses in Middle-earth. He got Shadowfax, learned of Theoden's condition, and rode as hard as he could to the Shire in just six days.
Charging around on Shadowfax, his lack of stealth drew the Ringwraiths; they felt the coming of his anger. He fought all nine Nazgul through the night, when they were strongest, and emerged unharmed. Aragorn and the hobbits spied the light and fire of that battle from miles away.
The Misty Mountains lay between the Fellowship and the Anduin, and the only safe route through, the Gap of Rohan, would take them right past Isengard, which he was committed to avoiding. So he first tried the Redhorn Pass, which failed, then went under the mountains through Moria despite Aragorn's warning.
Pippin had looked into the Palantir at Isengard and Sauron had seen him, so Sauron now appeared to think Pippin was the hobbit with the ring. Taking him to Minas Tirith would fix Sauron's attention there, not on hobbits sneaking into Mordor. There was compassion too, keeping Pippin from the Orthanc stone and temptation.
“Then darkness took me, and I strayed out of thought and time, and I wandered far on roads that I will not tell.”
“Naked I was sent back, for a brief time, until my task is done, and naked I lay upon the mountaintop.”
“Take it off! Take it off! Fool, take it off! Take off the ring!”
“It may take some time before he learns his error. We must snatch that time. We have been too leisurely.”
“but make no mistake, Minas Tirith would have fallen but for Gandalf.”
“The eagles are coming.”
“The Lord of the Rings from Gandalf's perspective.” https://www.youtube.com/watch?v=mXK08WeecxQ. Transcript summary by WhipScribe, https://whipscribe.com/transcript-pages/the-lord-of-the-rings-from-gandalf-s-perspective.html.