As with any science, advances are made by doing something stupid or accidental - the key is being able to do something intentionally stupid safely enough to do it again. That being said, wear proper safety gear - flame retardant clothes, blacksmithing gloves, a full face shield (i.e welding mask) not just safety goggles from a home improvement store. Once you're pretty sure you're not going to get hurt, then you can proceed.
Before you begin, you should know that this is not the cheapest way to do this, nor the most efficient, but it is effective, and will produce results you're looking for.
You will need:
- A crucible (an old/empty steel fire extinguisher with the top cut off will work great)
- Inert gas (you can almost always find some locally, but do your research first to find pricing and proper storage of it)
Find an extra-tall, nonporous crucible (steel should be just fine), and place it in the cold foundry, making sure it has a sturdy base. Add the magnesium into the crucible, and fill to the top with argon. Begin heating up the foundry and crucible. Argon is heavier than air, so it will push the air out as it fills the container, which if you're using a charcoal foundry, will be evident by a ring of charcoal around the crucible momentarily going cold as the argon replaces the oxygen. At this point, sit back, and go about the melt like you would anything else.
If you're casting it, the trick is getting the mold to be encased in an argon bath as well, for that you will need a much larger container and a lot more argon.
Look into how they melt titanium – it has all the same issues.