And while I'm at it I want to clarify something that many people get wrong, and that is the (in-)famous "183-day" rule. Most people believe that if you stay less than 183 days in a country during a calendar year, that you are not taxable there. But this is not true, it is actually the other way around: if you stay at least 183 days in one country you definitly have tax residency there, no matter what other circumstances apply. As an example: this was the case with Boris Becker, who almost went to jail for tax evasion, although he was less than 183 days in Germany in each of these years. He had his (main) residency in Monaco, but for some periods of time he lived in an apartment in Munich, that his sister(!) rented (the lease was on her name), but German tax authorities found out and could prove that she rented it only for her brother to live in, so it was considered his residency in Germany and therefore he was taxable in Germany. Because at the time there was no tax treaty between Germany and Monaco he had to pay taxes for his total(!) worldwide income.
Again, it depends all on the specific tax regulations and bilateral tax treaties (their main object is to avoid double taxation). Another example: you are a UK citizen and move to Germany for a project for 7 month, while keeping your flat in the UK. You are now taxable in both countries, and with your total worldwide income. To avoid this possible double taxation, the UK and Germany made a tax treaty and according to it's rules you will only be taxed in one country.
The US is an exception here, because they don't tax only by residency but by citizenship. Other countries (at least in the EU) treat this "taxable" question similar.