So if Jesus was without sin why did he undergo baptisim?
He did not need to, as St. John recognized. "But John stayed him, saying: I ought to be baptized by thee, and comest thou to me?" (St. Matthew 3.14)
And Jesus was not baptised with the Sacrament of Baptism, since such did not yet exist until he sanctified Baptism by His Baptism, at which point He Himself started a ministry of Baptizing (cf. St. John 3.22, 26 and 4.1-2). But he suffered to be baptised by St. John to manifest his humility:
"And Jesus answering, said to him: Suffer it to be so now. For so it becometh us to fulfil all justice." (St. Matthew 3.15)
And his glory:
"And Jesus being baptized, forthwith came out of the water: and lo, the heavens were opened to him: and he saw the Spirit of God descending as a dove, and coming upon him. And behold a voice from heaven saying: This is my beloved Son, in whom I am well pleased." (St. Matthew 3.16-17)