git fetch updates your remote-tracking branches under refs/remotes/<remote>/. This operation is safe to run at any time since it never changes any of your local branches under refs/heads. In other words git fetch gathers any commits from the target branch that do not exist in the current branch and stores them in your local repository. However, it does not merge them with your current branch. This is particularly useful if you need to keep your repository up to date, but are working on something that might break if you update your files. To integrate the commits into your current branch, you must use git merge afterwards.

git pull brings a local branch up-to-date with its remote version, while also updating your other remote-tracking branches. git pull tries to automatically merge after fetching commits. So all pulled commits will be merged into your currently active branch without letting you review them first.

In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.

Pictorial Representation

Below figure shows commonly used commands. As shown below, git pull brings the changes from Remote Repository (rightmost side) to local Workspace (leftmost side).

Git Commonly Used Commands
Git Commonly Used Commands


Following example demonstrate the usage of git fetch. Assuming remote repository is ahead of local workspace, below command will pull the new commits from remote-tracking branches and updates local repository.

git fetch origin master
git checkout master

If the remote master was updated you’ll get a message like this:

Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

If you didn’t fetch and just did git checkout master then your local git wouldn’t know that there are 2 commits added. And it would just say:

Already on 'master'
Your branch is up to date with 'origin/master'.