When Joseph discovered Mary was pregnant, he wanted to do what he thought was best – break off their engagement quietly. But God spoke to him in a dream and gave him clear instructions to follow. These instructions went against Jewish customs: a "good" man like Joseph would not marry a pregnant girl, and he would name his son after himself (like “Joe Junior” – hey, that’s kinda catchy).
However, the prophecy in Isaiah 7:14 had to be fulfilled: "All right then, the Lord himself will give you the sign. Look! The virgin will conceive a child! She will give birth to a son and will call him Immanuel." Immanuel means "God with us." Joseph did what God told him in his dream, and the world received their Savior in part because of Joseph’s obedience to God. You can trust that when God gives you instructions (either through His Word, the Bible, or even in a dream), obeying Him is always the best path.