After Allah (subhaanahu wa ta`aalaa) has said that He will forgive any sin other than shirk then how is a person to obtain forgiveness for this great sin?

Answer:

Allah (subhaanahu wa ta`aalaa) said, “Allah does not forgive that you make shirk with Him but he forgives everything other than that to whomever he chooses.” [4:48]

If the person falls into this sin of shirk, then he is a kafir and he has to come back into Islaam for a second time, and he has to make tawbah (seek repentance). But he should realise that Islaam wipes what came before it. As the Prophet (sallAllaahu ‘alaihi wasallam)has said in an authentic hadith, he asked the people and then he said, “Do you people not know that al Islaam destroys or wipes away that which preceded it.” Meaning that once a person comes into Islaam, his coming into Islaam serves as that which will wipe away his previous sins he fell into as well as the shirk he committed. This ayah is talking about the person who dies committing this crime of shirk.