It is virtually impossible, for most individuals, to immediately abstain from a bad habit. It requires enormous willpower and willpower is a very limited resource. Willpower appropriates too much brain fuel (glucose). Eventually the brain runs out of brain fuel and willpower fades, forcing us to fall back on bad habits. But there is a way to train your brain to release you from bad habits that does not demand too much brain fuel.
Instead of going cold turkey on a bad habit, continue to engage in the bad habit, but reduce your engagement in the habit by 50%. The brain will not fight you on this because it requires a minimum expense of willpower. Once you have trained yourself to engage in a bad habit at a reduced rate of 50%, that 50% becomes the new habit in about 30 days. After 30 days you can then reduce your engagement another 50%. After a few months you will be able to abstain from the bad habit altogether without any push back from your brain.