Most guinea pigs love to be petted as they are quite friendly and sociable. Although some guinea pigs do not like being petted very much. Don't worry if your guinea pig tries to squirm and escape. Some guinea pigs do not like affection so do not force it! Just like some humans are confident and some are shy.
Here are some simple tips on getting your guinea pig to trust you and visa versa:
Get them out lots. As I said before a lot of guinea pigs like to be petted.Spend as much time as possible with them. This will get them to trust you but don't do it to the point of scaring them.
Try to look them in the eyes and praise them if they do something well, they can hear you, you know.
On the flip side of point three if your guinea pig does something very naughty then just say in a firm voice "NO" and they will soon learn.