For lighter elements, the shells fill in order. Starting at the transition metals, an outer s orbital may fill before an inner d orbital, so the electron configuration of unioninzed cobalt is written $\ce{[Ar]}4\mathrm s^1\,3\mathrm d^7$, rather than $\ce{[Ar]}3\mathrm d^7\,4\mathrm s^1$.
There is a video diagramming the electron configuration of $\ce{Co}$, $\ce{Co^{2+}}$ and $\ce{Co^{3+}}$, thought it does not explain the reasoning, nor does it cover the less common $\ce{Co^{+}}$ ion, produced by photoionization or as found in some esoteric metal-organic compounds, or in the theoretical $\ce{CoCl}$.
That said, the situation becomes murky for transition elements, and downright turbid for lanthanides and actinides, where f orbitals are added. For example the outermost shells of $\ce{La, Ce and Pr}$ are $\ce5\mathrm d^1\,$, then $\ce4\mathrm f^1\,5\mathrm d^1$, and then $\ce4\mathrm f3$. What happened to the Pr d electron? My understanding is that energy levels are quite close for the larger outer shells, and it is not intuitive which orbital fills first.