Having a girl or a boy depends on the combination of chromosomes between the sperm and fertilized egg. A girl always has two X chromosomes, while a boy has one X and one Y. Sperms are either X-carrying or Y-carrying, while the egg is always X-carrying.
If an X-carrying sperm fertilizes the egg, it's going to be a girl. If a Y-carrying sperm fertilizes the egg, it's going to be a boy. Thus, the baby's sex is determined by which sperm gets to the egg first.
Some people have tried to separate sperm in the laboratory into X-carrying female sperms, and Y-carrying male sperms, with different reports of success.
There are many "wives' tales" out there, such as one tale that says that if a woman sleeps on her left side it's going to be a girl. However none have been proved in rigorous testing to be reliable.