I always have trouble figuring out how long to saute garlic for before adding it to a dish. How do I know when it is ready?
Not long at all. Usually 1 minute is enough.
If it starts to turn brown, it's been in there too long.
Exact time depends on the heat of the pan how you've cut the garlic (thick slices can go much longer than thin slices or minced), and if you're cooking it on its own, or with something else -- if you toss it in at the same time as onion, you're much less likely to burn it, but you might not get the exact same flavor out of it as it wasn't subjected to as high of heat.
When it's on its own (or with only crushed red pepper), minced, and the olive oil was shimmering when it went in, I maybe give it maybe 30sec before I toss in something else to cool down the pan.
If you saute the garlic by itself it really doesn't take very long--depending on the heat of your oil it can take from just a few seconds to a minute. It burns easily so you need to watch carefully, but I've found smell to be the best indicator that it's done--as soon as you smell that strong garlic scent it's ready even though it often won't look much different. Large pieces or whole garlic cloves are done (but not yet overdone) when they just start to turn brown, but with small pieces brown means burnt.
If you saute your garlic at the same time as (or after) the onions or other ingredients you won't get that strong scent and your garlic flavor will be less intense, but your garlic is also much less likely to burn. In these cases it's usually best to focus on whether the other ingredients are done to your liking and let the garlic take care of itself.
Start with olive oil in a cold pan. Add the minced garlic. Prepare whatever you wish to be added in advance. Turn on the heat to medium. Just keep smelling it. Once the harsh scent has gone away, and before it starts to get any more than slightly golden brown, add the other stuff to reduce the pans temperature. The garlic will be flavorful, but not acrid or burnt. You're on your own from there
Olfactorally, there is an unmistakable bloom of fragrance released. As soon as you smell that, the garlic is done.
Visually, the color will just start to change. You can use that as a queue to take a big sniff.
Use a medium to medium-low heat. High heat can overcook parts of the garlic to a tan color before most of it has even gotten cooked enough.
I used to cook all ingredients together, adding them to a frying pan in the order of decreasing cooking time, but that in turn is related to how much is in the pot. Garlic only needs 15-60 seconds, say--if it is getting the full heat on the bottom of the pan. If you have garlic and onions in the pan, then a garlic slice lying flat on the bottom can easily burn before another piece suspended in a nest of onion even becomes fragrant.
So, now, I cook the garlic by itself to perfection, either throwing it into a bowl while I cook everything else, or put everything else into a bowl temporarily while I cook the garlic exactly.
Warning: as you get experienced with garlic, you'll probably get more picky about it too. I went decades not caring too much, but once I realized how much is missing in undercooked garlic, and how bad overcooked garlic tastes, I'm too fussy.
BTW other answers mention mincing vs. thick slices or whole garlic. Personally I cook thin slices in every cuisine. I think they're attractive in the final product so mince is usually a lost opportunity. I also haven't ever seen a case requiring fried garlic to be any thicker than thinly-sliced. I'll certainly braise or roast whole cloves but I've never found cause to cook them in a frying pan.