Cables tend to snap at the attachment points. If it’s broken at the brake end, you may be in luck. If it wore through at the lever end, it’s much harder to fix on the trail.
If the cable broke close to the brake arm, because for instance it frayed at the attachment point, you might be able to create enough slack to re-attach it. Slide the brake lever closer to the stem on the handlebars. You might also need to cut the cable housing shorter if the housing runs the full length of the cable (front V brakes, for instance).
If the cable broke close to the lever, because for instance it wore through in the lever body, then you will have lost the soldered-on bead on the end of the cable. The brake lever typically needs this in order to work. Just “tying” the cable to the lever will not work as the cable will slip loose again. If you have locking pliers, you may be able to fashion them into a replacement lever but the safety factor is very low.
If you can’t safely fix the brake, do without it. Remove any pieces of the brake mechanism that may get caught in moving parts (for instance the straddle wire on cantilever brakes can catch on the tire), and continue your ride slowly.
Cutting brake cable housing
The brake cable housing is plastic coated, spiral wound wire. On the trail, cut through the plastic with a knife, and work the knife between the spirals Then bend the cable back and forth to break it. The end will be sharp and rough so try to file it down relatively flat before using the housing. Also make sure that the metal end isn’t folded in slightly and obstructing the cable’s path.