This is a relatively straight forward derivation that requires the understanding of work done.

Work done is the energy transferred in doing something on an object with a mass and is defined by:

W = Fd    (1)

Newton’s second law of motion tells us that F = ma

Therefore equation (1) becomes:

W = mad   (2)

W is the energy transferred, measure in joules, J
m is the mass, measure in kilograms, kg
a is the acceleration, measure in metres per second squared, m/s^{2}
d is the distance you move the object through, measure in metres, m

Since gravitational potential energy is the energy in lifting an object, you end up doing work  against gravity (or against the pull of Earth). This is because the force you are working against is the force of gravity. Therefore, the acceleration is the acceleration due to gravity and the distance is the height you work against gravity at. So a \rightarrow g and d \rightarrow h . The equation can now be written;

W = mgh

Since this type of energy is gravitational potential energy, the W  can just be changed into E_{p} , really you can use whatever symbol you want but to help an examiner mark your examination, use E_{p}  !

E_{p} = mgh