This usually is not a trail side repair. Just remember that you are diving a four-wheel drive vehicle and you can most often get home with either the front or rear drive disconnected. You will need to remove the drive shaft with the broken U-joint so that further damage is not done, then drive out in two wheel drive. If this is a front axle steering knuckle U-joint, the half shaft will need to be removed and a rag stuffed into the end of the open axle housing. If the drive shaft that needs to be removed has a slip yoke that splines into the back of the transmission, you will have to figure a way to keep the fluid in and the dirt out while getting where you can make permanent repairs.
Broken axles are also common.
The type of vehicle you drive will determine if you need a ride to town to buy a new axle and replace it where you broke it, or simply remove it and drive off in two wheel drive. Full floating axles are the easiest to deal with. Simply unbolt both axles, push out the broken end, re-install the axles and drive home in two wheel drive. On the other hand, if the wheel is retained by a C-clip inside of the differential housing, then you will have to go to town for a new axle. Engine fan contact with the radiator is another situation that I have seen on the trail.