From among the teachings of Allah's Messenger (peace be upon him) is to keep sins a secret matter. If someone commits a sinful act which is against the Commandments of Allah, or is against the moral character, or is such an act that may cause harm to one's honor, then he should keep it a secret and seek forgiveness from Allah in the darkness of night.
The Messenger of Allah (peace be upon him) said: "My entire nation is safe, except al-Mujahirin (those who boast of their sins). Among the Mujaharah is that a man commits an (evil) act, and wakes up in the morning while Allah has kept his (sin) a secret, he says: "O so- and-so! Last night I did this and that." He goes to sleep while Allah has kept his (sin) a secret but he wakes up in the morning and uncovers what Allah has kept a secret!" [Saheeh al-Bukhari]
Abdullah Ibn Masoud (May allah be pleased with him) related, `A man came to the Prophet and said: `O Messenger of Allah! I have mingled with a woman in the far side of al-Medina, and I fulfilled my desire short of actually having sexual intercourse with her. So, here am I, judge me according to what you decide.' Umar Ibn al-Khattab (May allah be pleased with him) then said: `Allah had kept your secret, why did not you keep your secret?' [Sharh Muslim]
Similarly, if one becomes aware of somebody else's sin, he should keep it a secret. Allah's Messenger (peace be upon him) said: "He, who relieves a hardship of this Dunya (world) for a believer, Allah will relieve (from him) a hardship of the Day of Resurrection; he who makes easy an indebted person, Allah will make it easy for him in the Dunya and the Hereafter; he who covers a Muslim (meaning his mistakes and shortcomings) , Allah will cover him in the Dunya and the Hereafter …" [Sahih Muslim]
Do not reveal your sins (whether major or minor), not even to your close ones such as your spouse or parents. Ask Allah for the forgiveness for the sins you committed and also ask Allah to help you to save from the same in the future.
Qawaaid wa-Fawaaid min al-Arabeen an-Nawawi by Shaikh Nathim Sultan, Tafseer Ibn Katheer, and others.