Keep your instrument in a controlled climate. Instruments made of wood are especially susceptible to expansion and contraction. In extreme cold, for example, acoustic guitars and other string instrument have been known to crack. Sometimes the crack is limited to the finish; sometimes it's the wood itself. Either way, this is not a repair you'll want to deal with or pay for. While more durable, solid body guitars and basses can develop cracks in their finish, called finish checking, when exposed to cold.
Controlled humidity can be good for some wood instruments — some manufacturers will place their instruments in humidor rooms for extended periods of time — but like anything, extremities should be avoided. In dry climates, and in the winter especially, it's a good idea to keep a humidifier in your instrument's case; then check it at least weekly to make sure it hasn't dried out. Exposed fret ends are a sure sign that your instrument is drying out. Also, exposing any instrument to direct hot sunlight will warp it, and it should go without saying that leaving your instrument in a hot car is a very bad idea and can quickly lead to serious and permanent damage.
Pianos are a little more bulletproof than smaller instruments, probably because they stay in one place most of the time, but still there are some obvious dos and don'ts. Don't put a water glass down on it, as the condensation will not only leave a mark but can cause some warping over time. Close the lid to keep out foreign objects and dust. You'd be surprised how easily things can collect inside there, including small pets. Close the keyboard lid to prevent anything from damaging the ivories. With electric keyboards, the same rules apply.
Get to know your instrument and be aware that parts will need to be replaced over time. Drums will need new heads; guitars need new strings. A teacher or a local music sales rep can help you with this. Don't be afraid to ask questions; time allowing, they may even show you how it's done.
Instruments like guitars and basses contain electronics, such as pickups and controls, that can be repaired or replaced. But unless you have knowledge and experience, leave these repairs to a proper luthier.
Properly caring for your instrument includes a proper setup, and once or twice per year is to be expected. Pay attention to your instrument and if it's difficult to play or it seems like something is amiss, a repair technician can do wonders. As you progress in your playing, you will start learning about the various aspects of your instrument and will be able to adjust many things by yourself; you'll find your own preferences and be able to manage them accordingly.
Knowing how to tune your instrument may seem a small factor, but an instrument that plays in tune and stays in tune will likely be in good shape and will aid your musical ambitions tremendously.
There has never been a time with more maintenance accessories on the market. These include guitar wax, guitar polish, fretboard conditioner, string cleaner and microfiber cloths. These all have their place, although a clean and slightly dampened rag can clean most grime off the guitar or bass. Do not use furniture polish, glass cleaner and the like, as they can contain alcohol, ammonia and other harsh chemicals that damage finishes.
Cases and padded gig bags are maybe the most important accessory for keeping your instrument in good playing condition. And when carrying your instrument in a gig bag, place a cloth over the headstock to prevent the string ends from tearing up the inside of the gig bag.
Many of these steps are second nature to professional players. As you learn, they will become so for you too. With a little attention, your instrument will be with you for years to come.