BLDC geared motor with encoder - How to wire the encoder? (6 wires)
This should be in the documentation of the motor or encoder, and that is the first place to look.
If you don't have any documentation, here is my best guess:
ABZ suggests it is an incremental encoder with channel A and B for quadrature encoding (giving direction and speed), with Z as the index pulse for getting absolute position once every rotation. FG is most probably Frame Ground, or maybe be the Fault signal.
How you wire it all depends on what you want to do with it, but knowing what each signal is should make it easy enough.