According to the current paradigm, galaxies form and reside in extended cold dark matter (CDM) halos and in turn are key tracers of cosmological structure. Understanding how different types of galaxies occupy halos of different masses is one of the major challenges facing extragalactic astrophysics. The observed galaxy properties depend on the environment surrounding the galaxy. Within the framework of most galaxy formation models the environmental dependence of the galaxy population is mainly due to the change of the halo mass function with large-scale environment. Such models make precise predictions for how galaxy clustering should depend on environment. We will illustrate this by presenting analytical models of dark matter and galaxy clustering along with results obtained from numerical simulations. With these results we can hope to obtain a better understanding of the link between galaxies and dark matter and thereby constrain galaxy formation models.