Fundamental group of a CW complex only depends on its $2$-skeleton
I was just about to write down my answer to an exercise in algebraic topology and I wanted to use the fact that $\pi_1(X)$ only depends on the $2$-skeleton of $X$ for any CW complex $X$. I am very sure we've had this fact in some of the topology lectures I've attended.
However, I'm not sure about what was the basic idea is here - please tell me if my thoughts are right, and if not, I'd like to see a short reasoning for this fact.
First we show that every map of CW complexes is homotopic to a cellular map. (I think the proof of this lemma was quite technical)
But now $\pi_n(X)$ is given by homotopy classes of maps $S^n \rightarrow X$, but a homotopy between such maps is just a map $S^n \times [0,1] \rightarrow X$, which by the lemma is homotopic to a map into the $(n+1)$-skeleton of $X$.
Is this the correct way to view the situation or is it flawed somewhere? I sadly don't remember when exactly we had proven said fact in a lecture, or I'd try to look it up in my scripts.
First of all, $\pi_n(X)$ is the set of pointed homotopy classes of maps; the basepoint matters. There's also a problem in your argument. When you replace $H : S^n\times [0, 1] \to X$ by the cellular map $H' : S^n\times[0, 1] \to X$, you get a homotopy from two potentially different maps, i.e. $H$ is a homotopy from $f$ to $g$, but $H'|_{S^n\times\{0\}}$ may not be $f$, it may have changed, so $H'$ is not necessarily a homotopy between $f$ and $g$.
In order to rectify this, let's recall the cellular approximation theorem.
Cellular Approximation Theorem: Let $X$ and $Y$ be CW complexes. Every continuous map $f : X \to Y$ is homotopic to a cellular map $f'$. Moreover, if $A$ is a subcomplex of $X$ such that $f|_A$ is cellular, then one can choose $f'$ such that $f'|_A = f|_A$.
Fix basepoints $p_0 \in S^n$, $x_0 \in X$. Choose a CW complex structure on $S^n$ with zero-skeleton $\{p_0\}$ and a CW complex structure on $X$ with $0$-skeleton containing $x_0$. Let $X^{(k)}$ denote the $k$-skeleton of $X$.
The class $\alpha \in \pi_n(X, x_0)$ is represented by a map $f : S^n \to X$ such that $f(p_0) = x_0$. As $f|_{\{p_0\}}$ is cellular, there is a cellular map $f' : S^n \to X^{(n)} \subseteq X$ such that $f$ is homotopic to $f'$, and $f'_{\{p_0\}} = f|_{\{p_0\}}$, i.e. $f'(p_0) = f(p_0) = x_0$. As $f'(p_0) = x_0$ and $f'$ is homotopic to $f$, $f'$ also represents the class $\alpha$.
If $g : S^n \to X$ is another representative of the class $\alpha$, then by the same argument, $g$ is homotopic to a cellular map $g' : S^n \to X^{(n)} \subseteq X$ with $g'(p_0) = x_0$, so $g'$ also represents the class $\alpha$.
As $f'$ and $g'$ both represent the class $\alpha$, there is a homotopy between them, i.e. a continuous map $H : S^n\times [0, 1] \to X$ such that $H(p, 0) = f'(p)$, $H(p, 1) = g'(p)$, and $H(p_0, t) = x_0$ for all $t \in [0, 1]$. Let $A = S^n\times\{0, 1\}\cup\{p_0\}\times [0, 1]$. As $H|_A$ is already cellular, $H$ is homotopic to a cellular map $H' : S^n\times [0, 1] \to X$ with $H'|_A = H|_A$, i.e. $H'(p, 0) = H(p, 0) = f'(p)$, $H'(p, 1) = H(p, 1) = g'(p)$, and $H'(p_0, t) = H(p_0, t) = x_0$. Therefore $H'$ is a cellular map and a homotopy between $f'$ and $g'$ (as pointed maps).
As $f'$, $g'$, and $H'$ are cellular, $f'(S^n) \subseteq X^{(n)} \subseteq X^{(n+1)}$, $g'(S^n) \subseteq X^{(n)} \subseteq X^{(n+1)}$, and $H'(S^n\times[0,1]) \subseteq X^{(n+1)}$. We obtain a class $\alpha' \in \pi_n(X^{(n+1)}, x_0)$ represented by $f'$ (and $g'$). Conversely, given $\beta' \in \pi_n(X^{(n+1)}, x_0)$, define $\beta = i_*\beta' \in \pi_n(X, x_0)$ where $i : X^{(n+1)} \to X$ is the inclusion map, i.e. if $\beta'$ is represented by $h$, then $\beta$ is represented by $i\circ h$. These two correspondences are inverses of each other, so we see that $\pi_n(X, x_0) = \pi_n(X^{(n+1)}, x_0)$; in particular, the fundamental group of $X$ only depends on its $2$-skeleton $X^{(2)}$.
More generally, the same argument shows that if $X$ is a $k$-dimensional CW complex and $Y$ is a CW complex, then $[X, Y] = [X, Y^{(k+1)}]$. If $X$ and $Y$ are pointed, then $[X, Y]_{\bullet} = [X, Y^{(k+1)}]_{\bullet}$.