Getting legal counsel has no bearing on this problem. If there have been no court proceedings concerning the child a custodial parent (with whom the child lives) can relocate with the child. The governing law in all 50 states is called the Uniform Child Custody Jurisdiction and Enforcement Act. Even after the parent moves with the child, California remains the child's home state until the child has lived in another state for six months. At that time the new state would become the child's home state. What this means is that a child being moved from California does not deprive the court in California from dealing with the custody and the parent left behind can ask the California Court, in your case, the Unified Family Court in San Francisco, to change custody to the parent left behind and order the parent wh0o moved to return the child to California and adjudicate custody proceedings. You should consult an attorney who has knowledge of and experience with the Uniform Child Custody Jurisdiction and Enforcement Act (UCCJEA).
To add to Mr. Rothstein's answer, you do have the ability to commence an action regarding custody with the Superior Court and seek primary custody and the right to relocate with the child. This is a major undertaking, however, very difficult without an attorney.