It is well known that for any abelian group $G$, and any CW-complex $X$, the set $[X, K(G,n)]$ of homotopy classes of maps from $X$ to $K(G,n)$ is in natural bijection with the $n^{\mathrm{th}}$ singular cohomology group $H^n(X; G)$ with coefficients in $G$.
My question is, is there a similar bijection if the group is nonabelian? Notice that we only need to consider $[X, K(G,1)]$. In particular, I am trying to figure out what $[X, K(G,1)]$ looks like if $G$ is a finite group.
Assume $X$ connected.
Yes, this is known. For pointed homotopy classes this is $\text{Hom}(\pi_1 X, G)$. This is 1B.9 of Hatcher, usually the first place one sees obstruction theory, and requires less work than the case of $n > 1$.
For unpointed homotopy classes of maps, one quotients by conjugacy of elements of $G$. As you point out in the comments below, this is 4A.2 of Hatcher.