St. Paul in 1 Timothy 1:4 and again in Titus 3:9 tells his readers to avoid questions into genealogies. However, Matthew and Luke both give long genealogies at the beginnings of each gospel about the lineage of Jesus Christ (which contradict each other). Why were genealogies provided if we shouldn't worry ourselves with them? Alternatively, if the genealogy of Jesus Christ is important, why does St. Paul counsel us to avoid questions on genealogy? Lastly, why don't the genealogies in Luke and Matthew agree?
I've often heard it said that one follows St. Mary and the other St. Joseph. This is incorrect. The better answer is that they are the same lineage but one follows the conventions of the Levirate law.
What is the law of levirate? levirate, custom or law decreeing that a widow should, or in rare cases must, marry her dead husband's brother. The term comes from the Latin levir, meaning “husband's brother.” The “brother” may be a biological sibling of the deceased or a person who is socially classified as such. I think, for the apostles, the practice of establishing one's salvation credentials by reference to one's ancestry is what was being disapproved of, since it had, by the time that was written, been established that one's 'salvation' entirely depends upon faith in God's Grace through Jesus The Christ of God, not upon earthly parentage. Matthew starts with Abraham and works forwards, while Luke works back in time from Jesus to Adam. The lists of names are identical between Abraham and David (whose royal ancestry affirms Jesus' Messianic title Son of David), but differ radically from that point. .
From gotquestions.org Most conservative Bible scholars today take a different view, namely, that Luke is recording Mary’s genealogy and Matthew is recording Joseph’s. Matthew is following the line of Joseph (Jesus’ legal father), through David’s son Solomon, while Luke is following the line of Mary (Jesus’ blood relative), through David’s son Nathan. Since there was no specific Koine Greek word for “son-in-law,” Joseph was called the “son of Heli” by marriage to Mary, Heli’s daughter. Through either Mary’s or Joseph’s line, Jesus is a descendant of David and therefore eligible to be the Messiah. Tracing a genealogy through the mother’s side is unusual, but so was the virgin birth. Luke’s explanation is that Jesus was the son of Joseph, “so it was thought” (Luke 3:23). Actually by this time it is likely that almost every Jew was in some way descended from David.