Concept:
The structure “had barely + past participle” is commonly used to indicate that one action had just happened before another occurred.
Step 1: Observe the helping verb.
The sentence already contains:
\[
\text{had barely}
\]
Therefore, the main verb must be in its past participle form.
Step 2: Check the options.
Among the given choices, the closest grammatically acceptable completion is:
\[
{\text{started}}
\]
leading to:
My friend had barely started to pull out of the garage when he realised that he had left the dog inside.
Step 3: Eliminate other options.
• had been starting --- incorrect structure.
• have started --- wrong tense.
• will start --- wrong tense.
Hence,
\[
{\text{Option (D)}}
\]