How can I repent from a sin so God would forgive me?
Allah the Almighty says,
“O you who have believed, repent to Allah with sincere repentance. Perhaps your Lord will remove from you your misdeeds and admit you into gardens beneath which rivers flow [on] the Day when Allah will not disgrace the Prophet and those who believed with him. Their light will proceed before them and on their right; they will say, "Our Lord, perfect for us our light and forgive us. Indeed, You are over all things competent" [Qur`an 66: 8].
Conditions of repentance
– Regretting having committed the sin;
– Desisting from it because it is an act of disobedience and not because it harms one’s body and property;
– Resolving not to return to it again.
It is obligatory to repent immediately from a disobedience; delaying repentance is itself a sin that requires repentance.
If the sin is connected to the rights of another human being, it is necessary to return the rights to their owners or to clear oneself of the obligation owed to others.
A Muslim must abide by God’s law and distance himself from whatever leads him to commit a sin. If for instance, his disobedience is connected to members of the opposite sex who are non-mahrams (persons to whom marriage is permissible), then a Muslim must avoid mingling with them and avoid khulwa (being alone with a non-mahram in a place where no one can enter upon them without their consent). In addition, a woman is required to observe hijab (the legal attire). If the disobedience is connected to money, a Muslim must espouse honesty and avoid deception. And if it is connected to vain talk, a Muslim must adhere to truthfulness and speak good words.
Adherence to Islam is a protection against disobedience. If a person repeats the same sin for which he has repented, he is considered to have committed it for the first time i.e. he is not liable for his previous sin and his repentance is not nullified. Abu Ubaida Ibn Abdullah narrated that the Messenger of Allah [peace and blessings be upon him] said, “The one who repents from a sin, is like one without sin.”
It is recommended for the person who repents to make istighfar (seek Allah’s forgiveness) abundantly, offer a two rak’a (cycle of prayer) repentance prayer, and accompany good people who will help him towards righteousness.
A person must conceal his sin and not expose himself. Abdullah Ibn Umar [may Allah be pleased with them both] reported that the Messenger of Allah (peace and blessings be upon him) said, “Avoid these filthy things that Allah has forbidden. Whoever has done any of them, let him conceal himself with the concealment of Allah and seek His forgiveness, for verily, whoever exposes his action to us, we will pass judgment against him according to the Book of Allah.” Filth refers to every abominable word or deed but in the hadith it refers to fornication.
Allah the Almighty knows best.
 Included by Ibn Majah in his Sunnan
 A raised chain hadith included by Al-Hakim and Al-Bayhaqi with an fair chain of transmission through Ibn Umar [may Allah be pleased with them both]. Included by Malik in Al-Muwatta` through Zaid Ibn Aslam in a mursal hadith (wherein the narrator does not mention the Companion who related it directly from the Prophet) and mentioned by Al-Hafidh in Al-Fat-h.