I heard differently from the Security guys in the Air Force. You alternate left and right passage around objects. That has a tendency to keep vector drift smaller.
That sounds plausible. If I start going left around an obstacle, I tend to keep going left around the next obstacles. If I start going right, I keep going right...
I think the most important effect of the various advice above is to focus the mind. If you are really concentrating on walking straight you are probably deviating less than if you just are walking. Any trick that you can use to keep focused is good - a mental placebo effect, so to speak.
The only sure way I know of to keep going strait is to find visual targets in the direction I need to go. When I reach that target I make a new target. This works really well when visibility is good, but it is quite hard to do accurately in dense forest.
Of course, being aware of your surroundings, sensing your environment (wind, sun etc) and looking back at where you came from is always very good advice.