  Modified gravity theories with the Gauss-Bonnet term
$G=R^2-4R^{\mu\nu}R_{\mu\nu}+R^{\mu\nu\rho\sigma}R_{\mu\nu\rho\sigma}$ have
recently gained a lot of attention as a possible explanation of dark energy. We
perform a thorough phase space analysis on the so-called $f(G)$ models, where
$f(G)$ is some general function of the Gauss-Bonnet term, and derive conditions
for the cosmological viability of $f(G)$ dark energy models. Following the
$f(R)$ case, we show that these conditions can be nicely presented as
geometrical constraints on the derivatives of $f(G)$. We find that for general
$f(G)$ models there are two kinds of stable accelerated solutions, a de Sitter
solution and a phantom-like solution. They co-exist with each other and which
solution the universe evolves to depends on the initial conditions. Finally,
several toy models of $f(G)$ dark energy are explored. Cosmologically viable
trajectories that mimic the $\Lambda$CDM model in the radiation and matter
dominated periods, but have distinctive signatures at late times, are obtained.
