In “Unfinished Tales”, J.R.R. Tolkien and subsequently his son, Christopher, added “The Quest of Erebor” story, which explains Gandalf’s account of how he arranged the expedition to Erebor with Thorin and lured Bilbo with the Dwarves. It’s quite interesting reading and good background information to “The Hobbit” and the turn of events in “The Lord of the Rings”. The whole story (which isn’t that long in the first place) is also included in “The Annotated Hobbit” by Douglas A. Anderson.
Gandalf and Thorin meet eachother in Bree, presumably by chance, and Thorin explains his troubles to Gandalf and invites him to journey with him to Thorin’s Hall. Gandalf agrees and urges Thorin’s expedition to Erebor. Gandalf explains his reasons much later, after the War of the Ring, to Gimli and Pippin:
“My chief reason was that of a captain, a member of the Council of War. When I met Thorin I had long known that Sauron had arisen again, and I expected him to declare himself soon. I knew that he was planning a great war and I surveyed all the lands in my mind. The urgent question was: which would he do first? Try to re-occupy Mordor; or attack the small but powerful strongholds of his chief enemies, Lórien and Rivendell?”
He continues to explain that he felt Sauron would get too strong if he took Erebor and from there was able to attack Lothlórien and Rivendell. He therefore also urged the Council to attack Dol Guldur, which resulted in Sauron fleeing to Mordor and being unable to attack Lothlórien.
“Then everything grew dark. And yet that was not his original plan; and it was in the end a terrible mistake. Resistance still had somewhere where it could take counsel free from the Shadows. How could the Ringbearer have escaped, if there had been no Lórien or Rivendell? And those places might have fallen, I think, if Sauron had thrown all his power against them first, and not spent more than half of it in the assault on Gondor.”
Gandalf gives an account of how he comes to think of Hobbits and Bilbo in particular and how he convinces the Dwarves to take Bilbo with them. I won’t spoil the interesting bits here, but it’s certainly worth reading and explains a lot about Gandalf and how things turned out as they did later on.