What is the difference between git pull and git fetch?

What is the difference between git pull and git fetch?

a) git pull fetches and merges changes, while git fetch only downloads changes
b) git fetch deletes remote changes, while git pull updates your repository
c) git fetch resets the repository, while git pull clones a new repository
d) Both commands do the same thing

Answer:

a) git pull fetches and merges changes, while git fetch only downloads changes

Explanation:

The difference between git pull and git fetch is that git pull fetches changes from a remote repository and merges them into your local branch, while git fetch only downloads the changes without merging them.

After fetching changes, you can manually merge them into your local branch. Pulling automatically merges the changes, saving you a step.

Knowing when to use each command helps you control the update process and avoid unintended merges.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top