Modern nonlinear optical materials allow light of one wavelength be efficiently converted into light at another wavelength. However, designing nonlinear optical materials to operate with ultrashort pulses is difficult, because it is necessary to match both the phase velocities and group velocities of the light. Here we show that self-organized nonlinear gratings can be formed with femtosecond pulses propagating through nanophotonic waveguides, providing simultaneous group-velocity matching and quasi-phase-matching for second harmonic generation. We record the first direct microscopy images of photo-induced nonlinear gratings, and demonstrate how these waveguides enable simultaneous $chi^{(2)}$ and $chi^{(3)}$ nonlinear processes, which we utilize to stabilize a laser frequency comb. Finally, we derive the equations that govern self-organized grating formation for femtosecond pulses and explain the crucial role of group-velocity matching. In the future, such nanophotonic waveguides could enable scalable, reconfigurable nonlinear optical systems.