For context, I'm in the US. I have this issue too! I'm awkward enough that people who know me usually don't offer hugs, or ask first. So if random people are also around, sometimes the friend will intervene on my behalf :)
Otherwise, what works best for me is figuring out when hugs are imminent and pre-empting them with a different gesture. This may vary depending on the context, but usually a handshake is an appropriate substitute. You could also go for a high-five or fistbump among friends.
If it's a situation where someone is giving out many hugs (for instance, exiting a wedding reception), you have time to prepare. When it's your turn, approach with a smile and your hand ready for a shake. Hopefully they take the hint! You can also observe what other people are doing - most likely you are not the only one to not hug.
For one-on-one situations where you suspect a surprise hug, keep a healthy amount of personal space between you (not distant, but enough that they can't just lean in on a moment's notice). This will give you a little more time to react.
If you realize someone is coming in for a hug anyways, just be up front about it: "oh, I don't do hugs, but thank you!". It may feel awkward to address, but it is usually much more awkward to end up in a stiff, at-arms-length embrace with an acquaintance! Of course sometimes they will insist, in which case I find it is best to just quickly do a hug and get it over with - but in my experience this is usually well-meaning extended family rather than workplace acquaintances.
Don't feel bad about (gently and politely) refusing a hug. People intend them as nice gestures, and making you uncomfortable would be the opposite of what they mean to do. Being honest will allow you both to have a pleasant interaction.
(Fun fact: I've ended a first date with a handshake after explaining I'm weird about hugs. And he still called me back for a second one!)