After Madinah became a safe haven [i.e. place] for Muslims, the Revered and Renowned Rasool صَلَّی اللّٰہُ تَعَالٰی عَلَیْہِ وَاٰلِہٖ وَسَلَّم allowed all of his companions to migrate to Madinah from Makkah. The first was Sayyiduna Abu Salamah رَضِىَ اللهُ تَعَالٰی عَـنْهُ. Then, other people also departed for Madinah one after another. When the disbelievers of the Quraysh became aware of it, they started obstructing migrating Muslims but the Muslims continued to migrate secretly. Within a period of time, many companions reached Madinah. Only those Muslims remained in Makkah who were either imprisoned by disbelievers or were too poor to migrate.
As the Beloved and Blessed Nabi صَلَّی اللّٰہُ تَعَالٰی عَلَیْہِ وَاٰلِہٖ وَسَلَّم had not yet received the Divine commandment of migration, he صَلَّی اللّٰہُ تَعَالٰی عَلَیْہِ وَاٰلِہٖ وَسَلَّم remained in Makkah. He صَلَّی اللّٰہُ تَعَالٰی عَلَیْہِ وَاٰلِہٖ وَسَلَّم also prevented Sayyiduna Abu Bakr Siddeeq and Sayyiduna ‘Ali رَضِیَ اللّٰهُ تَعَالٰی عَنْهُمَا from leaving. Hence these two devoted companions also stayed with him in Makkah.