firstNonzero[L_]:=Min[Select[Range[Length[L]], (L[[#]]) ≠ 0&]];

gTof[g_]:=
(n = Length[g];
l = Prepend[Table[RowReduce[Take[Transpose[g],-k]],{k,1,n}],{}];
Transpose[Reverse[Flatten[Table[Select[l[[k+1]], Not[MemberQ[firstNonzero /@ l[[k]], firstNonzero[#]]]&], {k,1,n}],1]]]
)

(* Here is our standard 3x3 example. *)

ex = 
{{1,x+z,x y},{0,1,y},{0,0,1}}

MatrixForm[gTof[ex]]