When you establish a good habit, being consistent makes it easier.
Our mind likes to be consistent. It works well when all of our actions are in alignment. Even better when our thoughts are in alignment with those actions as well.
For example, if you'd like to stop drinking coffee, you can take a good look at everything you associate with coffee. Maybe you also enjoy chocolate? Do you often walk by a bakery that reminds you of good coffee? Do you have a favorite cup? What are you doing during that time of the day when you usually drink coffee?
These associations can be gently rerouted. You can replace old ones with newer, healthier associations. When you experience a craving, make an effort to not indulge in thinking about it. Dwelling in desire will break down the consistency that you've been building up in your mind. Instead, investigate how it was triggered and what you can reroute to avoid similar situations in the future.
When you fall prey to your cravings, see it as a victory, not a defeat. Being hard on yourself only creates negative associations with your goal. You made it this far, now you'll have even more resolve going forward.
Your goals is to build consistency. It will get easier.