The ensign of the country of registry is flown at sea from a gaff fitted to the aft side of the mast and in port from the ensign staff usually, on a tug, fitted to a rail behind the funnel or up takes. The ensign of the country the ship is working in is hoisted at the starboard yard arm on the mast. This is known as a courtesy flag. The company (house) flag is hoisted at the port yardarm. Any old flag just won't do. Flag use in the uk is governed by maritime law as it is in most countries. Flags should be respected and looked after. Miss use of flags in foreign countries will often result in a fine or worse. Google marine flag etiquette for more details.
Jerry.