Female bears aggressively defend their offspring against any perceived danger. To escape an encounter unscathed, you must avoid appearing like a threat.
Speak firmly and authoritatively as you slowly back away. Stand tall and stay in a group if you're with friends, but don't look the bear in the eye or make sudden gestures. Don't run or throw rocks. If she charges, stand your ground; most charges are bluffs that end with her turning abruptly at the last moment. If she attacks, fight back (play dead if she's a grizzly). If your friend is attacked, make noise to try to scare away the bear. Join the fight against a black bear with sticks and rocks (aim for the head and nose) only if there are three or more of you to help. Otherwise, pull back at least 100 yards to a safe position. When the bear leaves, administer first aid.