Bad habits

How do I stop myself from starting a habit that I know is bad but I catch myself doing it?