When you do work on an object, you do work against a force and transfer energy in the process. The work done is defined as:
where F is the force and S is the distance moved in the direction of the force.
If you lift a mass through a height,
It can be seen that this is identical to the equation for gravitational potential energy:
In other words, by lifting the mass, work is done on the object resulting in a corresponding increase in its potential energy.
This effect is not confined to gravitational fields. For example, moving a charge in an electric field would require work to be done and a corresponding change in potential energy.