Generally, at the beginning of the divorce process, custody is negotiated and agreed upon by the parents. If the parents can’t agree, the court steps in, taking into account what is in the best interest of the child.
If your divorce is amicable and you can agree with your co-parent that joint physical custody is best for everyone involved, it is just a matter of the Court finalizing the agreement. If, however, the two of you are involved in a contentious situation, it may come down to you being able to prove to the judge your fitness as a parent. This is especially true when an opposing parent makes up stories or exaggerates the reasons for the divorce.
Of course, honesty is the best policy, but it is not unheard of for one parent to accuse the other of abuse in order to retain custody of the children. If you are in this situation, you need an experienced family law attorney on your side to represent you in court.