We describe the phase diagram of a 2+1 dimensional SU(2) gauge theory of fluctuating incommensurate spin density waves for the hole-doped cuprates. Our primary assumption is that all low energy fermionic excitations are gauge neutral and electron-like, while the spin density wave order is fractionalized into Higgs fields transforming as adjoints of the gauge SU(2). The confining phase of the gauge theory is a conventional Fermi liquid with a large Fermi surface (and its associated d-wave superconductor). There is a quantum phase transition to a Higgs phase describing the 'pseudogap' at lower doping. Depending upon the quartic terms in the Higgs potential, the Higgs phase exhibits one or more of charge density wave, Isingnematic, time-reversal odd scalar spin chirality, and Z 2 topological orders. It is notable that the emergent broken symmetries in our theory of fluctuating spin density waves coincide with those observed in diverse experiments. For the electron-doped cuprates, the spin density wave fluctuations are at wavevector (π, π), and then the corresponding SU(2) gauge theory only has a crossover between the confining and Higgs regimes, with an exponentially large confinement scale deep in the Higgs regime. On the Higgs side, for both the electron-and hole-doped cases, and at scales shorter than the confinement scale (which can be infinite when Z 2 topological order is present), the electron spectral function has a 'fractionalized Fermi liquid (FL*)' form with small Fermi surfaces. We also describe the deconfined quantum criticality of the Higgs transition in the limit of a large number of Higgs flavors, and perturbatively discuss its coupling to fermionic excitations.