The specific answer always depends on your employer and your exact situation, this article just gives some general information. We recommend speaking to a tax adviser too, as while health insurance is one issue, the more complicated one will usually be your tax situation.
I work on a freelance basis for clients outside of Germany
You're a normal freelancer. See our health insurance recommendation tool or all articles that help you as a freelancer.
I work with an employment contract outside of Germany
In most cases this means that you are considered a freelancer in Germany. We recommend doing the following things though:
Check if your contract can be transferred to a German subsidiary
Ask your employer if they can pay the employers contribution of 50% for healthcare, which is usual in Germany
If you're not from the EU, you should sign up for expat or full private health insurance
If you're from the EU, you can sign up for the public system as a voluntary member or expat or full private health insurance. We strongly recommend public or full private in this situation though
I have been posted for a temporary assignment to Germany
If you have been sent to Germany for a temporary assignment, your employer should have issued you the A1 and S1 forms. You can find more info here. Using those, you can generally stay insured in your home country for up to 24 months and avoid double social contributions while still having access to health care in Germany. This can also be the case if you are a freelancer; your freelancing activity is still registered in your home country and you are in Germany only on a temporary basis. If that is the case, you need to get the A1/S1 from your home insurance provider and present it to any public provider in Germany. Keep in mind that we can not process these applications.