I am reading Allen Hatcher's Algebraic Topology, and am trying to understand the proof to corollary 1.28:
For every group $G$ there is a $2$-dimensional cell complex $X_G$ with $\pi_1(X_G)\cong G$.
Since his book is available on his homepage, I will copy his proof below:
Choose a presentation $G=\langle g_\alpha\;|\;r_\beta\rangle$. This exists since every group is a quotient of a free group, so the $g_\alpha$s can be taken to be the generators of this free group with the $r_\beta$s generators of the kernel of the map from the free group to $G$. Now construct $X_G$ from $\bigvee_\alpha S_\alpha^1$ by attaching $2$-cells $e_\beta^2$ by the loops specified by the words $r_\beta$.
Which loops are specified here, and where do we attach the $2$-cells?
Edit: An example I thought of was a simple case where $G=\langle a, b\;|\;ab\rangle$, then we'd have $S_a^1\vee S_b^1$, and one $2$-cell which should "wrap around" both $S^1$? But then $\pi_1(X_G)$ would be trivial (contractible), unlike $G$?
Additionally, would there be an algorithm to work backwards, i.e. given a $2$-dimensional cell complex $X_G$ with some conditions (cells are disjoint except for the middle of the wedge), we can obtain $G=\langle g_\alpha\;|\;r_\beta\rangle$?
Given a group $G$, you could choose a set of generators $g_i$ and relators $r_i$ for the generators. Then construct a wedge of circles $X = \bigvee S^1$ with one circle for each generator $g_i$. The fundamental group of this wedge of circles is the free group $F(g_1, g_2, \cdots)$ on the generators of $G$.
Now $G$ can be realized as the quotient of $F(g_1, g_2, \cdots)$ by the subgroup $\langle r_1, r_2, \cdots \rangle$ generated by the relators. So if you attach a disk $D^2_i$ to $X$ by gluing the boundary $\partial D^2_i$ by the word $r_i$, for each word, then van Kampen's theorem would tell you that the fundamental group of the resulting 2-complex $X_G$ is precisely $G$. Basically we're pinching off the loops corresponding to $r_i$, so we get relators $r_i = 1$ added to the free group, which is precisely our group $G$.$^{(\bigstar)}$
For $\langle a, b | ab \rangle$, note that this is just isomorphic to $\Bbb Z$, because $ab = 1$ says $b = a^{-1}$. If you attach a disk to $S^1 \vee S^1$ along the loop $\partial D^2 \to S^1 \vee S^1$ given by the word $ab$, you're not going to get the trivial group: e.g., the loop going once around one of the circles in the wedge (i.e. corresponding to the word $a$) is nontrivial. In fact, it is going to be $\Bbb Z$, by van Kampen's theorem.
I don't understand your last question. If you have a cell complex, you can always compute it's fundamental group using van Kampen's theorem. It is precisely the fundamental group of the 1-skeleton (which is a wegde of circles upto homotopy equivalence) modulo the words the 2-disks are attached to the 1-skeleton by. This is all in Hatcher chapter 1.2 I believe.
$^{(\bigstar)}$Here's a nontrivial example which might help you understand the construction.
Take $G = \Bbb Z \oplus \Bbb Z = \langle a, b | aba^{-1}b^{-1} = 1\rangle$. Then we start with the wedge $S^1_a \vee S^1_b$ of two circles corresponding to $a$ and $b$ respectively. That has fundamental group $F(a, b) \cong \Bbb Z*\Bbb Z$ the free group on two generator. Now I want to glue a 2-disk along $aba^{-1}b^{-1}$. So start by taking a square (that's a 2-disk) with top and bottom labelled by $a$ equipped with an arrow (orientation) and the left and right sides labelled by $b$ equipped with some arrow (orientation). If you try to paste the square to the wedge of circles by $aba^{-1}b^{-1}$ you'll see you'll end up getting a torus. That indeed has fundamental group $G$. Visually, all we did was to make the loop corresponding to $aba^{-1}b^{-1}$ nullhomotopic, so in the fundamental group that gives me $aba^{-1}b^{-1} = 1$, i.e., $ab = ba$.