Since alliance and dissociation are always among the primary motivating factors of migration for the sake of Allah. We will divide our discussion of this into two broad areas:
1. Living among the disbelievers and its ruling.
2. Migrating from the abode of disbelief to the abode of Islam.
1. Living in the abode of disbelief
The jurists have explained the complimentary concepts of the "Abode of Disbelief' and that of "Islam" as follows:
The Abode of Disbelief is whatever land is ruled by the disbelievers, in which the laws of the disbelievers are supreme and political power is in their hands. These lands may be of two types. One which is at war with the Muslims and one which enjoys a truce with them. The determining factor is that it is ruled by the laws of the disbelievers; for it is the "Abode of Disbelief' or "Dar ulKufr", even if a large majority of Muslims live there. 
The Abode of Islam is any land that is ruled by the Muslims, where the Shari'ah is the supreme law and the Muslims hold political power. It is Dar ul-Islam, even if the majority of the population are disbelievers, so long as the Muslims rule it according to the Shari'ah. 
As Islam is the religion of dignity and authority, it was impossible to think of any Muslim submitting himself to the disbelievers; indeed it is forbidden for a Muslim to go to live amongst them and acknowledge their authority over him, because his presence amongst them would make him feel weak and isolated, and, then he would become docile and apologetic before them. He would first be called upon to approve of them, and then to follow them. But Muslims should be filled with morale and confidence, they should be leaders, not followers. They should hold the reins of power; no power should be above them but that of Allah. Therefore Muslims were forbidden to remain in countries where Islam is of no account, except when they are able to freely practice their religion and to observe it without any impediment, and without any fear that their presence there could damage them in any way. If this is not the case, then they must migrate to a better place where the authority of Islam is of some account. If they refuse to do so, while they are able, then they would have no further claims on this religion. About this Allah has spoken in Surat an-Nisa:
Verily! As for those whom the Angels have taken (in death) while they are wronging themselves (as they stayed among the disbelievers even though emigration was obligatory to them), they (angels) asked them, "In what condition were you?". They replied, "We were weak and oppressed on earth". The Angels asked, "Was not the earth of Allah spacious enough for you to migrate therein?" Such men will find their abode in Hell - what an evil destination! Except the weak ones among men, women and children who were unable to devise a plan, nor are they able to direct their way 
The Prophet (peace be upon him) said, “I am not responsible for any Muslim who stays among polytheists. They asked: 'Why, Apostle of Allah? He said: ‘Their fires should not be visible to one another.’, and he (peace be upon him) said, “Who joins the polytheists and lives with them then he is like them” and he (peace be upon him) said: “Migration will not end until repentance ends, and repentance will not end until the sun rises in the west.”
Al-Hassan Ibn Salih said: "whoever remains in the land of the enemy, will be treated like the disbelievers, so long as he was able to join the Muslims but did not do it. If one of the disbelievers accepts Islam, but still remains with the disbelievers, even though he was able to go to join the Muslims, he is to be treated like them; neither his blood nor his property will be protected. , 
Al-Hassan said: "If a Muslim emigrates to the land of the disbelievers, yet does not renounce Islam, he will be an apostate by virtue of his abandonment of 'Dar ul-Islam"' . (The Arabic text of the preceding passage refers to the land of the disbelievers as ‘dar ul-harb' and 'Ard ul-Adu', that is: the 'land of the enemy'; this indicates an active military opposition to the Muslims, as if in a state of war).
Ibn Hazm states that: "Whoever joins the 'land of war and disbelief, of his own free will and in defiance of whoever amongst the Muslims calls him to his side, is by virtue of this act an apostate, by all the laws of apostasy, in Islam. Whoever is able to kill him must do so. His property is unprotected, his marriage null and void, all his rights are swept away.
But whoever flees to the 'land of war' for fear of oppression, who neither opposes the Muslims in anything nor bears any malice towards them, and who was not able to find any refuge among the Muslims, is free of any guilt since he was compelled to leave.
As for someone who takes the Muslims as his enemies, offering his help and his service to the disbelievers, he is a disbeliever. But those who would emigrate to non-Muslim lands in search of wealth or prosperity to live under their protection, while they were able to go to live amongst the Muslims in their own land, but still do not withdraw themselves from the disbelievers; such people are not far from the fold of disbelief, and we can find no possible excuse for them, so we ask Allah's Forgiveness.
As for the person who lives in the land of Karmathians by his own free will, he is without doubt a disbeliever, because they are avowed enemies of Islam, disbelievers and apostates who only long for the destruction of the Muslims. Concerning those who live in a land where some heretic tendencies, leading to disbelief, are manifested, they are not considered disbelievers, as Islam is supreme in the land where it is possible to practice Islam openly; to confirm the message of the Prophet Muhammad (peace be upon him), read the Qur'an, establish the prayer, perform the fast of Ramadan and fulfil one's obligations entirely.
The words of the Prophet (peace be upon him), "I am not responsible for any Muslim who stays among polytheists" should clarify what we have said so far. It is clear that the Prophet (peace be upon him) refers here to the 'Dar ul-Harb', and because he (peace be upon him) appointed some Companions as governors of Khaibar (Jewish land), even though everyone who lived there were Jews.
If a disbeliever conquers a Muslim country, then acknowledges their religion (Islam), but assumes authority over them, and then claims any other religion than Islam, whoever lives with him, supports, or serves him in any way is a disbeliever, even if he claims to be a Muslim, as aforementioned. ,
Sheikh Hamad Ibn Ateeq, may Allah have mercy upon him, divided those Muslims who live in nonIslamic countries into three groups: Those who prefer to live amongst Non-Muslims because of their affection for them; those who live amongst non-Muslims yet ignore their obligation to denounce disbelief; and those who live amongst the non-Muslims but uphold their obligation to denounce disbelief.
The first group: stays amongst the disbelievers by choice and inclination, they praise and commend them, and are happy to disassociate themselves from the Muslims. They help the disbelievers in their struggle against the Muslims in any way they can, physically, morally, and financially. Such people are disbelievers, their position is actively and deliberately opposed to religion. Allah says,
The believers shall not take the disbelievers as allies in preference to the believers. Whoever does this shall never be helped by Allah in any way 
At-Tabari remarks that such a person would have washed his hands of Allah, and that Allah would have nothing to do with a person who actively rejects Him and denies His Religion. Allah , says:
0 you who believe! Do not take the Jews and the Christians as protectors, they are protectors of one another, whoever takes them as protectors is one of them.
Then, in the words of the Prophet (peace be upon him): "Whoever joins the,disbelievers and lives amongst them is one of them'
Abdullah Ibn Omar said: "Whoever settles amongst the disbelievers, celebrates their feasts and joins in their revelry and dies in their midst will likewise be raised to stand with them on the Day of Resurrection.  .
Muhammad Ibn Abdul Wahhab, may Allah have mercy upon him, mentioned that in the case of a Muslim whose people remained bound to disbelief and followed the enemies of Islam, he too would become a disbeliever if he refused to abandon his people, just because he found it difficult. He would end up fighting against the Muslims alongside his nation, with his money and life. And if they were to order him to marry his father's wife, but could not prevent that unless he migrates from his country, he would be forced to marry her. His alliance and participation with them in their campaign against Islam and their struggle against Allah and His Messenger is far worse than marrying his father's wife. He is also a disbeliever, about whom Allah has said:
You will find others who hope for your protection, and for that of their own people. But whenever they are sent to temptation, they yield thereto. If they do not withdraw from you, nor offer you peace, nor restrain their hands, then seize them and kill them wherever you may find them. In their case, We have given you a clear warrant against them. 
The second group: are those who remain amongst the disbelievers because of money, family or homeland. He does not demonstrate a strong attachment to his religion (Islam), nor does he emigrate. He does not support the disbelievers against the Muslims, whether in word or deed. His heart is not bound to them, nor does he speak on their behalf. Such a person is not considered a disbeliever merely because he continues to live among the disbelievers, but many would say that he has disobeyed Allah and His Messenger by not going to live among the Muslims, even though he may secretly hate the disbelievers. Allah has said,
Verily! As for those whom the Angels have taken (in death) while they are wronging themselves (as they stayed among the disbelievers even though emigration was obligatory to them), they (angels) asked them, "In what condition were you?". They replied, "We were weak and oppressed on earth". The Angels asked, "Was not the earth of Allah spacious enough for you to migrate therein?"
Such men will find their abode in Hell - what an evil destination!”
Ibn Kathir remarks: They were (wronging themselves) by refusing to emigrate. He continues by saying that this verse establishes a general rule which applies to anyone who is prevented from practising his religion, yet willingly remains among the disbelievers. There is no disagreement among the scholars, and the sources all state that this course of action is prohibited. 
Al-Bukhari relates that Ibn Abbas said that this verse was about "Some people from among the Muslims who stayed with the Pagans of Makkah, swelling their ranks, in the days of the Prophet. When fighting broke out some of them were killed and some wounded. Then Allah revealed the verse:
(Verily! As for those whom the Angels have taken (in death) while they are wronging themselves)”
Whatever excuses they may have offered were rejected by the revelation,
Say, 'If your fathers, your sons, your brothers, your wives, your kinsmen, the wealth which you have acquired, the commerce in which you fear a decline, or the houses you love - if these are dearer to you than Allah and His Messenger, and striving hard and fighting in His cause, then wait until Allah brings about His Decision (Torment). Allah does not guide those who are AI-Faasiqun.
Anyone who refuses to emigrate uses one of these eight excuses. But these excuses have already been rejected by Allah, Who has said that those who make such claims are disobedient to Him, and this was specifically with regard to those who chose to remain in Makkah which is the holiest place on earth. Allah required the believers to quit this place, and even love for it was not an acceptable excuse for refusal. How would such an excuse fare then for places other than Makkah? 
The third group: are those who may remain among the disbelievers without impediment, and they are two categories:
1. Those who are openly able -to proclaim their religion and dissociate themselves from disbelief. When they are able, they clearly disassociate themselves from the disbelievers and tell them openly that they are far from truth, and that they are wrong. This is what is known as 'Izhar ad-Din' or 'assertion of Islam'. This is what exonerates a person from the obligation to emigrate. As Allah has said: (Say, "0 Disbelievers, I do not worship what you worship and you are not worshipers of what I worship.. ).
Thus, Muhammad (peace be upon him), was commanded to tell the disbelievers of their clear disbelief and that their religion was not the same, nor was their worship, nor what they worshipped. That they could not be in the service of Allah, so long as they remained in the service of falsehood. He was commanded to express his satisfaction with Islam as his religion and his denial of the faith of the disbelievers. Allah SWT says:
Say (0 Muhammad): "0 mankind! If you are in doubt about my religion (Islam), then know that I do not worship what you worship besides Allah, rather I worship Allah Who causes you to die, and I am commanded to be among the believers. And (it is inspired to me): Direct your face (0 Muhammad) towards the religion Hanifan (Islamic Monotheism), and never be one of the Mushrikeen. 
Therefore, Whoever does this is not obliged to emigrate.
Asserting one's religion does not mean that you simply leave people to worship whatever they please without comment, like the Christians and the Jews do. It means that you must clearly and plainly disapprove of what they worship, and show enmity towards the disbelievers; failing this there is no assertion of Islam.
2. Those who live amongst the disbelievers, and have not the means to leave nor the strength to assert themselves, have a license to remain. Allah SWT, says,
Except for the weak ones among men, women and children who are unable to devise a plan, nor to direct their way.
But the exemption comes after a promise to those who remain among the disbelievers, that,
Such men will find their abode in Hell - What an evil destination!
It is an exemption to those who could not devise a plan nor find any other way out. Ibn Kathir remarks: "These were people who could not rid themselves of the disbelievers, and even had they been able to do so, they would not have been able to direct their way" 
And what is wrong with you that you fight not in the Cause of Allah, and for those weak, ill-treated and oppressed among men, women, and children, whose cry is: "Our Lord! Rescue us from this town whose people are oppressors; and raise for us from You one who will protect, and raise for us from You one who will help'
So in the first verse, Allah swt mentions their situation, their weakness and inability to find any way to extricate themselves, and in the second, He mentions their plea to Allah to deliver them from their oppressors and to give them a protector, a helper and guide to victory. For these people Allah swt says:
For these there is hope that Allah will forgive them, and Allah is Ever Oft-Pardoning, OftForgiving.
Al-Baghawi commented that: "A Muslim who becomes a captive of the disbelievers must flee, if he is able, as he would not be permitted to remain under them. If they make him give his word that he would not run away if they were to release him, he should give them his word, but then he must try to escape; there would be noguilt upon him for his lie, since they had obligated him themselves. But if he had given them his promise, in order to ingratiate them to himself, he would be obliged to escape, just the same, but must also offer penance for his wilful deception of their trust"
The rulings about travel to disbelieving countries (Dar ul-Harb) for purposes of trade are broadly detailed. If you are able to assert your faith, while not supporting the disbelievers, then this is permitted. Indeed, some of the Companions of the Prophet (peace be upon him) travelled to some countries of disbelievers in search of trade, among them Abu Bakr as-Siddiq. The Prophet (peace be upon him) did not prevent them from this, as Imam Ahmad points out in his Musnad and elsewhere. 
If you are unable to assert your religion or avoid supporting them, then it is not permitted to venture amongst them for trading purposes. The subject has been addressed by the scholars and the relevant support for their position will be found in the Prophet's Ahaadeeth. Allah has required all believers to uphold their faith and to oppose the disbelievers. Nothing is allowed to undermine or interfere with these obligations.
While this is quite clear from many different sources, we still find a carefree attitude among many Muslims today with regard to this subject. The forming of friendships with those who are rightly our enemies, and establishing communities in their countries has been trivialised. Remarkably, some Muslims even send their children to the West to study Islamic Law and Arabic in European and American universities! This will stand as an absurd monument to the foolishness of those Muslims of the twentieth century, who sent their children to the disbelievers to study Islamic Law and Arabic!
Our scholars have warned us enough of the dangers which these questions raise, and they have carefully explained the perils of such educational exchanges, and of the desire of the disbelievers to corrupt the minds of our youth to turn them away from Islam, so we should take time to consider what we are doing. 
2. Emigration from the Abode of Disbelief to
"Hijrah" is the Arabic word for emigration. It means, ultimately, to separate or abandon. In religious terminology it means to move from a non-Muslim place of abode to a place where there is a presence of Islam . It is a fact that those whose religion is Islam; which is based on directing all kinds of worship to Allah, rejecting and showing hatred to polytheism and disbelievers; will never be left at peace by the antithesis of Islam, as Allah has said:
They will not stop fighting you until they turn you away from your religion, if they are able 
and He says about the people of the Cave:
For if they come to know of you, they will stone you or turn you back to their religion, then you will never prosper 
and finally, about the disbelievers declared aim, Allah says:
Those who disbelieved said to their Messengers: "We will drive you out of our lands, or you shall return you to our religion". So their Lord revealed this to them: "Surely We shall destroy the Zaalimun (disbelievers)”
Likewise, Waraqah Ibn Nawfal said, anticipating the mission of the Prophet "1 wish I could be young at the time when you will be driven away by your people." He said, "Will they throw me out?". "Yes, Nawfal replied, no one has ever come with a thing such as this who was not then driven away by his own people". So it was that the Quraish first drove the Prophet (peace be upon him) from Makkah to Ta'if, then to Madinah; and some of his Companions emigrated twice to Abyssinia. 
The Hijrah is a vitally important aspect of Islam; it is at once the guiding principle of alliance and dissociation and the supreme example of it. The Muslims could never have abandoned their homes and families, exposing themselves to the pain of separation and the hardship of migration if it had not been indispensable to the practice of their religion and the assertion of Islam in the land. Allah promised these emigrants a great reward in this world and the next, saying:
Those who left their homes for the sake of Allah after having suffered persecution shall be settled in comfort in this world but in the next is the greater reward if they but knew. Those who were steadfast and who upon their
Lord totally depend.
Hijrah has a comprehensive meaning as understood in Islam. It is not simply just the act of moving from one place to another; from a non-Muslim country to a Muslim country. Ibn al-Qayyim explains that it is, in fact, an emigration of the body and the spirit. A physical movement from one place to another and a spiritual migration to Allah and His Messenger (peace be upon him). It is this second migration which constitutes the real migration, as the body simply follows the soul. Thus, the meaning of moving from one thing to something else is that the heart moves from the love of something other than Allah to love of Allah; from servitude of something or other to the service and worship of Allah; from fear of something or other to hope in and reliance upon Allah. It is Allah Who is the object of one's hope and fear; prayers are addressed to Him; and He is the One before Whom one feels humility and awe. This is the meaning of flight which Allah mentions in the command: (So flee to Allah). 
This is the essence of monotheism (Tawhid); that you abandon all else and flee to Allah. Flight is from something to something else, and in this case it is from whatever is odious in the sight of Allah to whatever He loves. This is essentially an expression of either love or revulsion. Whoever flees a thing exchanges an undesirable thing for something better, in response to his own preference. This kind of migration may be more or less strongly motivated depending upon the degree of love in one's heart. The stronger or deeper the love, the more complete and secure is the migration. If this love is shallow then the migration is less secure, and this may continue to the point of complete indifference. 
The rulings regarding actual physical migration from the lands of the disbelievers to a land of Islam is as follows:
Imam al-Khattabee  points out that in the early days of Islam physical migration was recommended but not required, as Allah says:
Whoever migrates for the sake of Allah will find refuge and great bounty in the earth . 
This was revealed when the pagan persecution of the Muslims at Makkah was on the rise, after the Prophet has left for Madinah. But after this they were subsequently commanded to follow him there in order to be with him. They were required to cooperate as a single community, to learn their religion from the Prophet and to get an understanding of it directly from him. At this time the greatest threat to the Muslim community was posed by the Quraish, who were the masters of Makkah. After Makkah fell, the obligation was again lifted and migration became once again a matter of preference. Bearing this in mind, we are in a better position to understand the report of Muawiyah who related that the Prophet (peace be upon him) said: "Migration will not end until repentance ends, and repentance will not end until the sun rises in the west". And that of Ibn Abbas who said: "The Prophet (peace be upon him) said, on the day of the conquest of Makkah, 'There is no migration (after the conquest), except for Jihad and good intentions, and when you are called for Jihad, you should immediately respond to the call” . The chain of narrators in Ibn Abbas's Hadith is Sahih, but that of Muawiyah is disputed by some. 
Because of the significance of the Hijrah, especially in the early days of Islam, Allah swt severed the ties of mutual support between the Muslims who migrated to Madinah and those who chose to remain in Makkah, saying:
Indeed those who believe and who migrated and who struggle in the Path of Allah with their wealth and their lives, and those who gave them shelter and who gave them help, these are allies of one another. But those who believe yet did not migrate have no part in this alliance until they too migrate. If they seek your assistance in faith you must help them except against a people with whom you have a treaty. Allah is well aware of what you do 
Following this, Allah praises the migrants and the Helpers (Muhajirun and Ansar) saying:
Those who believe and who migrated and who struggled in the Path of Allah, and those who gave shelter and aid, these are the true believers. Forgiveness and bountiful provision are theirs. 
We have already discussed the Muhajirin and the Ansar, what we will look at now are those believers who did not make the Hijrah, but who stayed in Makkah the time of conflict. Allah says:
Verily! As for those whom the angels take (in death) while they are wronging themselves (as they stayed among the disbelievers even though emigration was obligatory for them), they (angels) say to them: "In what condition were you?" They reply: "We were weak and oppressed on earth". The angels say: "Was not the earth spacious enough for you to emigrate therein?" Such men will find their abode in Hell - What an evil destination. Except for the weak ones among men, women and children who are unable to devise a plan, nor to direct their way. For these there is hope that Allah will forgive them, and Allah is Ever Oft Pardoning, Oft-Forgiving. 
Al-Bukhari relates that Ibn Abbas said that some Muslims used to live among the disbelievers, increasing their population during the Prophet (peace be upon him) era. They were killed or injured in the fighting, so Allah swt revealed: (Verily! As for those whom the angels take (in death) while they are wronging themselves).
Therefore, the believers who did not emigrate but who remained in their homes had no share in the war booty, nor in its fifth part, except in the battles in which they took part, as Imam Ahmad has stated. This is indicated by a Hadith mentioned by Imam Ahmad and also reported by Muslim on the authority of Sulaiman Ibn Buraida, on the authority of his father, that: "Whenever the Prophet (peace be upon him) appointed a commander over an army or a detachment, he advised him privately to be mindful of his duty to Allah and to guard the welfare of the Muslims who were under his command. Then, he said, "Fight in the name of Allah, and for His Sake. Fight whoever disbelieves in Allah. Do not embezzle the spoils, nor break your pledge, nor mutilate the dead bodies, nor kill children. When you meet your enemies, the polytheists, invite them to three things and if they make a positive response to you, accept it and withhold yourselves from doing any harm to them. Then invite them to migrate from their lands to the land of the Emigrants and tell them that if they will do so, they will have (all the privileges and obligations) that the Emigrants have; but if they refuse to migrate, tell them that they will be like the Bedouin Muslims and will be subjected to the Commands of Allah swt which are applicable to other Muslims and they will not be entitled to any booty nor Fai' unless they perform Jihad along with the Muslims. If they should refuse, demand Jizyah from them; but if they agree to pay Jizyah, accept it from them and restrain your hands from them. But if they refuse to pay Jizyah,seek Allah's Succour and fight against them...” 
The preceding discussion about Hijrah may be summarised as follows:
1. Migration from the lands of disbelievers to the lands of Muslims was mandatory in the time of the Prophet (peace be upon him), and it is still obligatory till the Day of Judgement. The obligation which the Prophet (peace be upon him) lifted after the conquest of Makkah was that of taking up residence near him. Whoever accepts Islam while living among those who are at war with Muslims must leave to make his home among the Muslims. 
This is supported by the Hadith of Mujaashi' Ibn Mas'ud who said: "I took my brother to the Prophet after the Conquest of Makkah, and said, "0 Allah's Apostle! I have come to you with my brother so that you may take a pledge of allegiance from him for migration." The Prophet (peace be upon him) said, "The people of migration (i.e. those who migrated to Madinah before the Conquest) enjoyed the privileges of migration (i.e. there is no need for migration anymore)." I said to the Prophet (peace be upon him), "For what will you take his pledge of allegiance?" The Prophet (peace be upon him) said, "I will take his pledge of allegiance for Islam, Belief, and for Jihad” 
2. It is obligatory to leave the lands of the Bidah(innovation). Imam Malik said: "None of you may remain in a country where the Companions are cursed' .
3. It is obligatory to leave a place where forbidden practices are rife since it is mandatory for Muslims to demand observance of the Law . In this regard, Ibn Taymiyyah said, "The state of a place reflects the state of a person. It is possible to be sometimes a Muslim and at other times a disbeliever; sometimes sincere and at other times hypocritical; sometimes good and pious and at other times rotten and corrupt. Thus, a person becomes like the place of his abode. The migration of a person from a land of disbelief and profanity to one of faith and probity is an expression of repentance and of his turning away from disobedience and perversion to belief and obedience. This is so until the Day of Resurrection."
4. One must flee persecution and oppression. This is to be counted as one of the many blessings of Allah swt that he has given His license, to whoever fears for himself and his own safety, to go and find some sanctuary for himself. The first to do this was Abraham,~ who, when he was threatened by his own people said: (1 will emigrate for the sake of my Lord), (29:26), and, (1 am going to my Lord, He shall guide me), (37:99). Then there was Moses: (So he escaped from there, vigilant and fearing for his life, and said "My Lord deliver me from these oppressors" ), (28:21 ).
5. In times of epidemic, people were required to leave the city and remain in the hinterland until the threat of disease had passed. The exception to this is in times of plague. 
6. If one fears for the safety of his family or the security of his property then he must also flee since security of one's possessions is like the safety of one's person. 
Finally, migration, like anything else, is in the first instance a matter of intention, for the Prophet (peace be upon him) said: "Indeed actions are but by intention, and each will be rewarded according to his intent. So whose goal is to migrate for Allah and His Messenger, his migration is for Allah and His Messenger, and whose aim is to migrate to some worldly gain or to take the hand of a woman in marriage, his migration is to that which he has sought."
Oh Allah please accept my hijrah and expiate my sins ameen