If you have a bad habit that you've reinforced for years, you know how difficult and frustrating it can be to correct it. Whether it's biting at your fingernails, cracking your knuckles, or jamming your thumb against the back of the guitar neck, the easiest solution to correct these habits is to form them correctly from the beginning.
A very common bad habit for beginning and experienced guitarists alike, is the fundamental problem of poor posture.
In the realm of guitar playing, each hand plays a major role. They must work together with flawless synchronization, and must be relaxed and loose and free of tension to perform their jobs. Of all the jobs they need to accomplish, supporting the weight of the guitar shouldn't be one of them. (In fact, one way to reduce the tension in your fretting hand while playing barre chords is to make use of the weight of your arm. You let the guitar support your weight. Not the other way around!)
So how do we correct this?
Start in a seated position. Assuming you're a right-handed guitarist, place the guitar on your left leg. And elevate that leg a few inches with a footstool. (These are very inexpensive, but you can experiment with a shoe box or a brick, etc.) This forces the fretboard to become a bit more upright, and allows the wrist to be in proper alignment with the forearm. This allows your fretting hand to operate with its full range of motion, and with a minimum of tension. That allows for the best finger independence, and economy of motion.
Once you gain a bit of experience with this posture, you'll be able to relax your shoulders, wrists, and hands, and you'll remember how that feels. And you'll want to replicate that feel every time you play. In a standing position, you'll replicate that posture, supporting the weight of the guitar on your shoulder with a guitar strap. Make sure your guitar strap is short enough to produce the same posture. Rather than the elevated leg to rest the guitar, your shoulder strap will stabilize the guitar in the same relative position. Same position, same feel. Same ability to relax the shoulders, wrists, and hands. Same complete range of motion, finger independence, and economy of motion.
In the long run, establishing good habits by starting slowly and cautiously will save you a lot of time and effort.