Tuning the strings on your guitar is one of those things you only get good at by practise. It's easy to buy a tuner and tune your guitar BUT, how do you make sure you've done everything you can to keep it in tune. Please allow me to share a few tips based on 30 years experience and countless hours working on countless guitars for other players and customers.
1. Machine Heads.
Machine heads can slip. They can wear over time and some will even slip when still brand new! Tension is on the gears all the time so if they are in poor condition or generally not 100%, they can be a major cause of your guitar losing tune. Check that yours don't move fractionally when you bend notes (increasing the tension) or don't just plain slip because they want to at standard pitch (440Hz).
2. Use Good Strings.
This obviously speaks for itself and as players ourselves (at Pure Tone®), we believe that string quality is vital. Be aware though that it does not matter one cent where your string is manufactured, just make sure that is manufactured properly and that it is manufactured to world standards. There simply is no 'best string in the world'. That is a myth put around by lots of people who want you to buy their product so don't feel pressured to buy any particular brand, even ours. Find a brand that you yourself like, and try to stick with it. That way you'll have some consistency to gauge (pun intended :) by with respect to you and your guitar.
The nut of your guitar is a friction point. Make sure it does not bind the string in anyway. Graphite powder can help but we've personally found that setting it up right and using a good quality nut will give you the results you need. Check with a luthier to be sure yours is spot on if you are unsure. Oh yeah, make sure it doesn't move. :-)
4. Tremolo Units.
One of the major causes of pain in staying in tune is the tremolo unit. There are too many types to cover them all here but the whole goal of them all is to return your strings to pitch after the tension has been changed. To help yours do this job, firstly be sure there are no friction points causing you problems. Secondly, be sure the spring tensions are all set right (equal pull across the unit according to string tension) and thirdly make sure that the body of the tremolo is returning to position correctly. These are only three points and there are plenty more, but are the primary ones to consider.
5. Stretch Tune Your Strings.
Make sure you stretch your new strings in. Experience will teach you how far to go with this but my personal rule of thumb is to stretch them enough so they stop going out of tune by no more than a semi-tone when you give them a full bend (3/4 width of the neck). For me this leaves guaranteed life in them for a full night or full days session. To stretch a string, simply tune it to pitch (a little higher is ok) and then just pull the string away from the body of the guitar. How far? Well if the body starts to move then you're obviously lifting the weight of the guitar with the string, so that would be a good place to stop. Trial and error this one, everyone is different how they approach it. Experiment with it.
6. Fit Your String Correctly.
This means a few things and one of the major ones is to make sure you wrap it on the machine post correctly. For me it means bringing the string back around and over the insert point on the first wrap. All subsequent wraps (normally 2-3) will then go under these. This does two thing: (a) Puts tension on the wrap which helps prevent slippage and (b) Puts the string in a downward direction to the machine head post which helps keep the string in the nut. Be careful though that you get the overall balance of this right because you don't want too much tension at the nut remember (see Point 3 above).
7. Use A Good Tuner.
Speaks for itself really. Another really good option is a tuning fork. Super useful AND it doesn't need batteries!
In conclusion, I hope this helps a little. Staying in tune is pretty straight forward after a while once you get your guitar set up right and you learn how best to manage the strings on it.
Have fun and enjoy your playing!