Some arguments, none entirely conclusive, are reviewed about the origin of magnetic fields in neutron stars, with emphasis of processes during and following core collapse in supernovae. Possible origins of the magnetic fields of neutron stars include inheritance from the main sequence progenitor and dynamo action at some stage of evolution of progenitor. Inheritance is not sufficient to explain the fields of magnetars. Energetic considerations point to differential rotation in the final stages of core collapse process as the most likely source of field generation, at least for magnetars. A runaway phase of exponential growth is needed to achieve sufficient field amplification during relevant phase of core collapse; it can probably be provided by a some form of magnetorotational instability. Once formed in core collapse, the field is in danger of decaying again by magnetic instabilities. The evolution of a magnetic field in a newly formed neutron star is discussed, with emphasis on the existence of stable equilibrium configurations as end products of this evolution, and the role of magnetic helicity in their existence. A particularly puzzling problem is the large range of field strengths observed in neutron stars (as well as in A stars and white dwarfs). It implies that a single, deterministic process is insufficient to explain the origin of the magnetic fields in these stars.