Header

How are "git fetch" and "git pull" different?

git fetch vs git pull

When it comes to updating your repository with changes that have been pushed to the remote copy by other members of your team, you'll be able to use one of two commands:

We'll look at the differences between them and why you'd choose one over the other in certain scenarios.

Fetch

git fetch allows you to retrieve updated changes from the remote repository and review them, without affecting your local working copy. This is useful if you just wish to take a look at what your team is working on, but keep your own code exactly as it is.

You just need to run the following command:

git fetch origin

Where origin is the name of the remote repository you're connecting to. Therefore, you can run git fetch as often as you like without any adverse affects to your own code.

Pull

git pull retrieves updated changes from the remote copy, but unlike git fetch, it also automatically merges them into your own work.

This is useful when you're working on the same feature as one or more of your team members, and you want to be sure you're all working on the same version of your code.

To take advantage of this feature, simply run:

git pull

Developers normally run git pull less often than git fetch, perhaps at the start of the day, or when they start working on a new feature.