welllllllll no one has the complete right answer .. cuz there isn't one!
I'm gonna speak in very general terms:
all commercial ports have pilots (it is an OLD profession) ..... country laws require ships use local PILOTS. As I mentioned the relationship between the captain/master gets complicated but TECHNICALLY the pilot is '
just an adviser' which local law requires the master to have on board.
Many times the Mater doesn't do the actual 'driving', either hands on the controls or what's called 'having the conn'. The person with the conn has the masters permission to issue orders directly to the person who may be handling the controls (helmsman) or may have actual 'hands on' the controls. No matter who has the conn, the master is responsible ... THAT'S LAW. Deciding to ignore a pilot is a high risk action but it happens, sometimes with good reason. Giving the pilot the conn happens but not always. Every situation is different. I've had pilot come aboard who didn't speak a word of english and others come aboard drunk, and others who came aboard, collected their fee and found a chair and said and did nothing until it was time to get off!
In some ports there are different pilots for different parts of the evolution. In San Francisco one pilot is responsible for entering the Bay, depending on where you are going a different pilot may come on board - Sacramento pilot- and often a special docking pilot is employed. It depends. Last time I was in Coz they had only 'harbor pilots' and not docking pilots. Docking pilots are common when tugs are the norm and Coz' has few tugs as there is little commercial freight traffic. When a docking pilot and tugs are used the ship is usually sitting 'dead', everything in neutral .... but the master is STILL RESPONSIBLE!!!!
https://www.marineinsight.com/careers-2/maritime-pilot-and-his-duties/