When i restring my guitar, i do not insert my string into the peg hole first. I wind the guitar string a few rounds around the peg. When winding, you have to pull the string, this is to make sure that the string do not unwind.
After the guitar string is in its coiled position around the peg, i push down the coiled string so that there is no space or gap between those coiled string.
Then i insert the guitar string through the peg hole. I insert the string just above the coiled guitar string around the peg. There should be plenty of space as you pushed the coiled string down in the above step, if you did not push down the coiled string around the peg, it will act like spring and it will be difficult to insert the guitar string through the peg hole.
The last step is to cut away excess length of string. If the guitar string is loose, you have make adjustment at the bridge, push the screw at the bridge up or pull it down till the strings are fixed at the bridge. Tighten using rotating the peg head.