The introduction of desired genes into the male and/or female germ line or sex cells needed to pass on genes from one generation to the next.