There are two different stories about the birth of Jesus, and two different answers.
In Matthew's Gospel, after the birth of Jesus Mary fled to Egypt, where she stayed until King Herod died. She then returned to Judea but, being warned by God, turned aside and went to Galilee instead.
In Luke's Gospel, Mary went to Jerusalem after the birth of Jesus, for her ritual purification, then travelled immediately to Galilee.
Joseph and Mary traveled to Bethlehem , as it was told to go to their respective hometowns for the census.
yesbie
a person
Joseph and Mary went to Bethlehem to be counted in a census so they could be taxed.
Mary and Joseph went to Bethlehem for the census because it was a requirement by the government for all residents to return to their ancestral hometowns to be counted.
Mary traveled to Bethlehem by riding on a donkey with Joseph.
Joseph's ancestral home was Bethlehem. However, at the time he took Mary as his wife he was living in Nazareth.
Bethlehem
She traveled there with her husband Joseph, whose family was from Bethlehem.
Mary and Joseph were obliged to go to Bethlehem for the census by the Roman authorities. In a sense you could also say God led them, since it was ordained that Christ would be born in Bethlehem.
Matthew's Gospel indicates that Mary and Joseph were from Bethlehem in Judea. While returning from Egypt, they were warned in a dream to turn aside and go to Nazareth in Galilee, instead. Luke's Gospel says that Mary and Joseph were from Nazareth in Galilee. They travelled to Bethlehem for a census, then returned to Nazareth.
a census