Are you allowed to swear by God?
Yes, swearing by God is permitted in Islam. However, there are two types of oaths (swearing) which have different rules. The first one is a casual, rather than solemn, oath. For example many Muslims say “Wallahi (by Allah) this” or “Wallahi that” in casual conversation. This type of swear is not solemn, therefore breaking it has no legal consequences. For example if someone casually says “Wallahi I will do that tomorrow” and they do not do it, if their swear was casual, then even if they do not do the thing, there is no blame upon them.
God does not hold you responsible for your unintentional oaths, but He holds you responsible for your intentions. God is Forgiving and Forbearing.The Quran, verse 2:225.
The other type of oath is the solemn oath or vow. When you clearly state something and swear by Allah, and in your heart you mean this oath to be solemn, then breaking it will be sinful unless you make atonement (kafāra) for it.
God does not hold you accountable for your unintended oaths, but He holds you accountable for your binding oaths. The atonement for it is by feeding ten needy people from the average of what you feed your families, or by clothing them, or by freeing a slave. Anyone who lacks the means shall fast for three days. That is the atonement for breaking your oaths when you have sworn them. So keep your oaths. Thus God makes clear His Revelations to you, that you may be grateful.The Quran, verse 5:89.
If you make a binding oath to do something harmful, or if you later regret the oath and find a better alternative, it is recommended to break the oath and make the atonement for it.
Narrated Aisha: That her father (Abu Bakr) never broke his oath till Allah revealed the order of the legal expiation for oath. Abu Bakr said, "If I ever take an oath (to do something) and later find that to do something else is better, then I accept Allah's permission and do that which is better, (and do the legal expiation for my oath ) ".Sahih al-Bukhari Vol. 6, Book 60, Hadith 138
However, if you vowed by God to someone (if you made a promise to them) and later you wish to break it, it is considered bad manners to do so. Therefore besides making atonement for it, you must try to get that person’s permission and forgiveness. But there is no legal ruling on breaking promises to a person, this is just a matter of etiquette.
Source on breaking promises: