Explain the difference between Git clone, pull, and fetch.

git clone, git pull, and git fetch all retrieve data from a remote repository, but they differ in scope and in whether they touch your current working branch.

Key Points: • git clone is a one-time operation that downloads an entire repository, including all history and branches, and sets up a local copy with origin configured. • git fetch downloads new commits and updates remote-tracking references (like origin/main) but does not change your current branch or working directory at all. • git pull performs a fetch and then automatically merges (or rebases) the new commits into your current branch, immediately changing your working directory. • fetch is the safer choice when you want to review incoming changes before deciding to integrate them. • clone is only used once per new local copy of a repository; fetch and pull are used repeatedly afterward to stay in sync.

Example: A developer clones a new project once with git clone, then uses git fetch daily to check what's changed on the remote before deciding whether to git pull those changes into their working branch.

Code Example:

git clone https://github.com/example/project.git
git fetch origin
git pull origin main

Interview Tip: A concise interview answer is:

"git clone is a one-time full copy of a repository, git fetch downloads new commits without touching your branch, and git pull fetches and immediately merges those changes into your current branch. I use fetch when I want to review changes first, and pull when I'm ready to integrate them right away."