If you need to pee really bad and can't make it to the restroom or toilet right away you can try crossing your legs which can help hold in the pee.
Or also try holding yourself down there which also stops the pee from coming out until you can reach the restroom.
But if you're near a restroom and can make it to the restroom then you should use the restroom and pee as soon as possible because holding in your pee too long can damage your kidneys and bladder.
If you're sitting down in a car you can try moving your body around which helps to prevent your bladder muscles from releasing the pee which is what I've done before until I could reach a restroom.
You can also stop yourself from peeing by taking your mind off the pee and distract yourself by doing something else.
But really you should get to the toilet as soon as possible and release the pee.