Start with g1. Since M is torsion free, nothing kills g1, hence g1 spans a free submodule of M.
Bring in the subsequent generators, g2 g3 etc, one by one, as long as the resulting submodule remains free. Let S be the largest free submodule in this ascending chain. The next generator produces a larger submodule that is not free. Call this troublesome generator g, and let J be the submodule spanned by S and g.
By assumption, g and S are linearly dependent. Find a nontrivial linear combination that equals 0. For some x in R, xg lies in S. Since g is outside of S, x is not 1.
Multiplication by x implements a module homomorphism on M. Restrict this homomorphism to the submodule J. The image lies in S. The image is a submodule of a free module, and is free. Because M is torsion free, the kernel of this homomorphism is 0. In other words, J is isomorphic to its image, which is free, hence J is free after all. Therefore all the generators can be folded in, and M is free.
Remember that the rank of M is no larger than the number of generators.
Note, Q is an infinitely generated torsion free Z module that is not free.