How does a magnetic field differ from a gravitational field?

The biggest difference is that a gravitational field is mathematically classified as a tensor field while magnetic fields, or actually electromagnetic fields, are vector fields. This means that it takes 4x4=16 components to define a gravitational field in general while it only takes 4 components to define an electromagnetic field. The number 4 comes up because spacetime is 4-dimensional.

Gravitational fields are determined only by the mass ( or mass-energy) of a body. Charged and uncharged massive particles produce the same gravitational field pound for pound ( well...the electromagnetic energy has its own mass so it does contribute a bit ).

Magnetic fields are produced by charged particles in motion, and depend on the charge and velocity of these particles, but not on their mass. Magnetic fields are 'polar' fields with a North and South polarity.

Gravitational fields have no polarity at all. At large distances, gravitational fields diminish as the inverse square of distance from their source.

Magnetic fields at large distances from their source, decrease as the inverse cube of the distance.

You can only detect magnetic fields by using charged particles to measure their deflection.

Gravitational fields can be detected by using anything to measure a change in velocity.