If you need to fix a flat tire, the first thing to do is remove the wheel. This article teaches you how to remove a rear wheel that is attached by a thru axle. (If you have a quick-release axle, see the how-to details here.)
Video: Bike Maintenance: How to Remove a Rear Wheel with a Thru Axle
Removing the Wheel
First, put your bike in a repair stand and shift the chain to the smallest cog. If you're in the middle of your ride or you don't have a bike stand, you can flip the bike upside down to work on it. Shifting to the smallest cog will help the wheel slide out more easily.
If your derailleur has a clutch that increases tension on the chain, turn it off.
Next, loosen the lever on the axle and spin it counterclockwise until all the threads are completely loose. Support the wheel and pull the axle out.
To get the wheel out smoothly, pull down on the tensioning arm and back on the body of the derailleur. The wheel should slide right out.
Reinstalling the Wheel
When you're done with your work, it's time to reinstall the wheel. Start by adding a thin film of grease to the threads on the axle.
Get the derailleur out of the way by pulling it down and back. It also helps to make sure one of the smallest cogs engages with the upper section of chain.
Check that the wheel is fully seated in the dropouts before reinstalling the axle.
Now reinstall the axle. If the axle doesn't slide in smoothly on the first try, remove it and check the wheel's alignment before trying again. Screw in the axle and close the lever. Make sure it's tucked out of the way and isn't touching the bike's frame.
If the lever closes too easily and is touching the frame, it's probably not tight enough. Open the lever and tighten the axle. Then check everything again.
If your derailleur has a clutch, turn it back on.
Finish by spinning the pedals and making sure that the gears shift normally.