Take the big cap off the master cylinder, lay a piece plastic wrap over it ( check to make sure the plastic wrap you use is compatible to brake fluid) snap the cap back on and quickly change the hoses. The cap and the original rubber seal allowed air to enter the top of the master cylinder and the rubber seal acted as a diaphragm. The plastic acts as a seal so air won’t enter . Used to use parts bags when opening brake systems to prevent fluid loss. Some will leak out, but not much.
You can also use a similar trick when replacing temp senders by taking the radiator car off and putt a plastic bag over the radiator fill and reinstall the cap. The idea is to not let the venting designed in the system to work, just remember to take the bag off when done and watch for spills