The most important thing to realize is that 3 workers per mineral is the max you would want. It is not necessarily optimal however. The third worker is not as effective as the first 2. Once you have more than 2 workers, one of them will always be "hanging around" waiting for its turn to be useful. Therefore, if you have an expo with less than 2 workers per patch, you would do better to move some workers there. You will get more minerals per minute by having 2 workers per patch at your main and 1 per patch at your expo than you would with 3 workers per patch at your main.
With that in mind, here are some answers:
How to keep track of how many you have at a specific base?
Make sure all your mineral patches and gas geysers are visible on the screen. Now double click on one of your workers. This will select all your workers. At the bottom middle of your screen you'll see wireframes of all of them, 8 per row. if you have 3 rows full, that's 24 workers, which is a decently saturated base. "Full" saturation would be about 24 on minerals and 6 on gas, or 30. But if you have an expo, you're better off moving some of them... (Note that MULEs do not conflict with SCV's for mining time, so they should not factor into your counts.)
When you expand, should you build workers from that base or transfer?
This depends on the situation. If your expo is far away from your main, and there are potentially enemy forces in between, then transferring is probably a bad idea. If you have more than 2 workers per patch in your main, and your natural is nearby and well defended, then transferring makes sense. In my experience, Zerg players usually expand before they have much more than 2 workers per patch, while a 1 base terran or protoss will often build up 30 workers on one base before expanding.
**Rebuilding after some being killed **
I'm not sure what the question is here - you can just rebuild them like you normally build them.
Transferring when minerals run out
There is no automatic way to have workers move to an expansion when minerals or gas run out. However, you can listen for the voice that says "mineral patch depleted" and start transferring them. You can also look for the idle worker icon that pops up on the lower left hand side of your screen, that will alert you to a worker who is not doing anything.
Race Specific Tidbits
Protoss can chronoboost workers to help get an economy up and running, or recover from an attack.
Terrans can get by with less SCVs if they have a lot of orbital commands to summon MULEs with.
Terrans can load SCV's into command centers, then fly them to a new base.
Zerg players need to remember to build more drones to replace drones used to build buildings.
Let's do some math here:
- Average Rush Distance: 50 seconds
- Drone Build Time: 17 Seconds
- Minerals gathered per second: 1*Drones
- Starting Drones: 6 (+50 Min)
So if he rushing you with his initial 6 this means you should have enough to build at least 2 more drones by the time he arrives. This would leave you with 8 drones to his 6. If he waits for his 7th, then you should be looking at 9-10 Drones vs his 7.
The key point here is: You should always have more Drones!
Now in 2v2 I can see how this would be an issue... if your ally doesn't help you, but in 1v1 you should always have a leg up on anyone Drone rushing.
Now many where you're falling down is Drone Micro. The key to good Drone micro is two things
- Try to surround his Drones
- If you right-click on Minerals (harvest), your Drones gain unit walking
If you're ever in a situation where he has a surround and you don't, just click minerals. This will remove his surround. Don't let your Drones get caught behind each other as you want to get a good surround. Finally, if he's dancing in and out, just mine more minerals and build more Drones. He's not harvesting and you are, and that means you can gain an even larger advantage.
Best Answer
It doesn't count as harvested until the drone deposits it at the nexus. The drone keeps carrying the mineral or gas until you send it to a nexus to deposit it.
Related to your second question, here's a good practice when switching a drone from minerals to gas: right click the assimilator, then immediately press "C" ("cargo"), which causes drones to deposit any minerals at the nexus before continuing to the assimilator. That way you can pick any three drones and send them to harvest gas: if they're carrying minerals, they'll immediately deposit them before going to the assimilator, and if they're not carrying minerals they'll ignore your "C" and go right to the assimilator.
(Credit for the best practice: @Emmett)