I see the line "a $G$-torsor is a principal $G$-bundle" many times.
I am trying to see how they are related. You are welcome to take your own definition of principal $G$-bundle.
Definition of $G$-torsor that I am familiar with is as follows :
Let $G$ be a Lie group. A $G$-torsor is a manifold $X$ with a free and transitive action of $G$.
I do not have any idea how to associate a principal $G$-bundle $(P,M,G,\pi)$ with this. Should I take $P=X$? But the action of $G$ on total space of a principal bundle is in general not transitive. Only transitive action I see in a principal bundle is the action of $G$ on fibers $\pi^{-1}(x)$.
So, fixing a principal $G$-bundles $\pi:P\rightarrow M$, I am not getting just one $G$-torsor but a collection of torsors $\{\pi^{-1}(x)\}$ indexed by elements of $M$.
So, I do not think a $G$-torsor gives a principal $G$-bundle. But, a collection of $G$-torsors $\{P_m\}$, indexed by elements of a manifold $M$, might give a principal $G$-bundle over $M$, if these are glued together. Is that correct?
There are two notions of torsor, or there is the notion in the definition you gave (aka principal homogeneous space), and also a relative version (and more generally a categorical version). The relative version intuitively means that the fibers are principal homogeneous spaces, plus a local triviality condition.
See the section about this in Wikipedia's article principal homogeneous space under other usage.
Since relative versions of things are so common in algebraic geometry, its not surprising to see the more general notion at the article Torsor (algebraic geometry), while "Torsor" redirects to the page for principal homogeneous space.