A Wohnsitz exists if you have a home you can use, even if you are rarely there. Habitual abode usually applies after more than six months' stay.
If you are resident in two countries, the double tax treaty decides which country has priority.
Full guideTax residency in Germany: when worldwide income enters the pictureRelated terms
General information on German tax law, not advice on your individual case.