Giant flares on soft gamma-ray repeaters that are thought to take place on magnetars release enormous energy in a short time interval. Their power can be explained by catastrophic instabilities occurring in the magnetic field configuration and the subsequent magnetic reconnection. By analogy with the coronal mass ejection (CME) events on the Sun, we develop a theoretical model via an analytic approach for magnetar giant flares. In this model, the rotation and/or displacement of the crust causes the field to twist and deform, leading to flux rope formation in the magnetosphere and energy accumulation in the related configuration. When the energy and helicity stored in the configuration reach a threshold, the system loses its equilibrium, the flux rope is ejected outward in a catastrophic way, and magnetic reconnection helps the catastrophe develop to a plausible eruption. By taking SGR 1806 - 20 as an example, we calculate the free magnetic energy released in such an eruptive process and find that it is more than $10^{47}$ ergs, which is enough to power a giant flare. The released free magnetic energy is converted into radiative energy, kinetic energy and gravitational energy of the flux rope. We calculated the light curves of the eruptive processes for the giant flares of SGR 1806 - 20, SGR 0526-66 and SGR 1900+14, and compared them with the observational data. The calculated light curves are in good agreement with the observed light curves of giant flares.