The IITMSAT project is a student satellite initiative of the Indian Institute of Technology Madras. It is a nanosatellite with a scientific mission involving measuring proton and electron fluxes in the Earth's magnetosphere to characterize their interactions with electromagnetic waves. The scientific mission places requirements on the attitude control subsystem that the attitude be autonomously maintained such that one axis of the satellite tracks the geomagnetic field direction. This must be achieved using minimal hardware due to power and mass restrictions. A system to track the time-varying geomagnetic field vector is designed by a combination of analytical and numerical techniques. A novel approach of switching between two control laws, each controlling a subset of the states, is taken to achieve a high level of performance with purely magnetic actuation.