I keep dying as a medic. I don't run directly into the battle, I just stay behind my allies, but I'll still die before I can deploy an Übercharge.
Do you have any tips for me? How should I defend myself? What medigun should I use?
As the medic, your primary objective is to stay alive. If your ally is running somewhere stupid, don't follow him. Don't latch on to a single teammate and just keep him alive; keep everyone around you overhealed all the time.
If you are a good medic, your allies will protect you. If an enemy is coming straight for you, run towards an ally who can take him. Generally, as a medic, you should not be engaging in combat unless it is your last option.
If you keep your team healthy, they will have no problem keeping you alive too. Just stay out of the way.
I'm going to restate this point because it's extremely important: do not follow your teammates into certain death.
Medic can be a frustrating role because they can't do anything without competent teammates, but every team needs one.
Don't just stay behind your allies - stay as far behind them as you can while still healing them. If you are with a large group, you don't need to be up at the front line. Stay back a bit and they can fall back to you if they become low on health. If possible, hang behind corners while doing this. If the other team can't see you, they can't shoot you.
Staying alive as medic is extremely important - if someone you are healing is going into a dangerous situation that you don't think you can live through abandon them. The best medics value their lives above their teammates' lives. The best teammates value their medics' lives over their own. If a teammate complains about you "leaving them to die," calmly explain to them that, while they can respawn quickly, your ubercharge meter does not.
Medigun choice is very situational. As a very general rule of thumb, I find it useful to go with the regular medigun on offense and the kritzkrieg on defense. This is not a solid rule, though. If you are on offense and the defensive team is not building high level sentries, you may find that the faster charging kritzkrieg is more appropriate. Similarly, if you are on defense and need to destroy a sentry nest, running with the medigun is probably a better idea. Experiment with different guns and you'll get a better sense of what is right in every situation.
All good answers, I'll just add a few tips of my own.
If there is a very good player, it can sometimes help to be his dedicated medic. Of course, you should heal others, as well as people on fire. The "best player" should usually be with one of the following classes as they have most benefit from overheal and can do good damage: Heavy, Soldier, Demoman, Pyro. So if you find this good player, latch on to him and see how it goes; it can sometimes pay to follow him into what normally would be a dangerous situation.
Keep an eye on your back... spies love to backstab a medic and then heavy combo. So watch out for people coming up to you from behind. Melee them a couple of times if possible. If you are using voice, call out there's a suspicious guy behind you. Spotting spies is a skill that takes time to learn. You can generally check if someone is a spy by following these concepts:
Other than that use the map to your advantage. Stand behind corners while healing people you can see besides you.
I will follow up these two particularly well-crafted answers with this...be able to defend yourself.
You will often get into a situation where the offensive class you're healing dies, or somebody comes up from you from behind. In this case, you need to be able to save your own arse (if you can).
Once that happens, I highly recommend switching to either your saw or dart gun of choice. I prefer the Blutsauger (darts that heal you each time you hit the enemy), or the Ubersaw (that builds up your uber by 25% for each hit)
Make sure that you strafe successfully enough that your enemy has difficulty hitting you, and you should at least be able to survive.
(Of course, if you're being doused in pyro fire all bets are off...)
Move. All the time keep moving, even if you're only healing one person and no one else appears to be around, weave and bob and jump up and down like a madman behind your team (though only jump a little bit), and swivel your mouse around a bit too.
A moving target is very hard to hit - especially for a spy trying to sneak up to your back and stab it, and especially for a sniper trying to predict your movement and get a clean headshot, which are your two greatest threats at the back of the line.
Swiveling the mouse around also serves a second purpose - keeping you alert to things behind you. Not just spies and a few sneaky scouts/pyros that get behind your lines, but teammates who might be hurting badly and on the retreat, or a tell-tale sniper dot that tells you that you should be hiding behind a corner and not standing out in the open (and also, quit jumping around who told you to do that?)
Movement will keep you safe, not just as a medic, but as any class, an erratically moving target is harder to hit.