Tsemo's answer addresses the first part of your question. To answer the second, for $G$ discrete, a $G$-bundle $p:P\to M$ is in particular a covering space for $M$, and so every path in $M$ has a unique lift (which happens to be the horizontal lift for the flat connection discussed in Tsemo's answer). So a closed path $\gamma:[0,1]\to M$ based at $x\in M$ lifts to the path $\tilde\gamma:[0,1]\to P$ (starting at some fixed $q\in p^{-1}(x)$). Since $\tilde\gamma(0)$ and $\tilde\gamma(1)$ lie in the same fibre, they differ by an element of $G$, so we can write $\tilde\gamma(1) = \tilde\gamma(0)\cdot \Lambda(\gamma)$. In fact, homotopies on $M$ also lift to $P$, and so $\Lambda$ factors through $\pi_1(M)$ to give a map $\lambda:\pi_1(M)\to G$. It is not too hard to show that $\lambda$ is a homomorphism. $\lambda$ essentially defines $P$ (for $M$ connected): if $\tilde M$ denotes the universal cover of $M$, then $P \simeq \tilde{M}\times_\lambda G$.
You can find a nice discussion of covering spaces in Hatcher's Algebraic Topology (particularly Section 1.3, Lifting Properties). The lifting arguments above apply more generally to principal bundles with flat connections (even if $G$ is not discrete): a discussion of flat bundles and holomorphy homorphisms is contained in Section 2.1.4 of Morita's "Geometry of Characteristic Classes".