The International Regulations for Preventing Collisions at Sea (COLREGs) govern every vessel. The core idea: some vessels must keep clear (give way), others must stand on (maintain course and speed).
Between two sailing vessels on different tacks, the vessel on port tack gives way. On the same tack, the windward vessel keeps clear of the leeward one. A sailing vessel keeps clear of vessels restricted in ability to manoeuvre, fishing vessels and vessels not under command.
Power-driven vessels generally keep clear of sailing vessels. When two power vessels meet head-on, both alter course to starboard. Any vessel overtaking another keeps clear until finally past and clear.