As Jedi says, turn your hips and shoulders to face uphill in a similar manner to cornering. Drop the downslope pedla and get all your weight on it. Pull up on your outside grip and push down on the inner one to get even more pressure on your outside pedal. Ride neutral by moving your body weight over the cranks rather than hanging off the bars and over the back wheel. In general riding your weight should be nicely centred over the cranks. Bring it forward for corners for extra grip on the front and move it back to help the front wheel over trail obstacles. Keeping your front wheel tracking is more important than the rear so if it starts to slide get some more weight over the front.
If all else fails, really weight up the front by moving your weight right the way over the bars. The extra grip will get the front end up the hill enough to just miss the tree. Allow the rear to slide low.
You'll still hit the tree with your body but as the front wheel is past the tree and your weight is forward you can push the bike forward under you and around the tree using your elbows against the tree for leverage. If you've come to a complete standstill, apply the brakes and pull yourself up 😉