OK, here are some information about git pull
and git fetch
, so you can understand the actual differences... in few simple words, fetch gets the latest data, but not the code changes and not going to mess with your current local branch code, but pull get the code changes and merge it your local branch, read on to get more details about each:
git fetch
It will download all refs and objects and any new branches to your local Repository...
Fetch branches and/or tags (collectively, "refs") from one or more
other repositories, along with the objects necessary to complete their
histories. Remote-tracking branches are updated (see the description
of below for ways to control this behavior).
By default, any tag that points into the histories being fetched is
also fetched; the effect is to fetch tags that point at branches that
you are interested in. This default behavior can be changed by using
the --tags or --no-tags options or by configuring
remote..tagOpt. By using a refspec that fetches tags explicitly,
you can fetch tags that do not point into branches you are interested
in as well.
git fetch can fetch from either a single named repository or URL, or
from several repositories at once if is given and there is a
remotes. entry in the configuration file. (See git-config1).
When no remote is specified, by default the origin remote will be
used, unless there’s an upstream branch configured for the current
branch.
The names of refs that are fetched, together with the object names
they point at, are written to .git/FETCH_HEAD. This information may be
used by scripts or other git commands, such as git-pull.
git pull
It will apply the changes from remote to the current branch in local...
Incorporates changes from a remote repository into the current branch.
In its default mode, git pull is shorthand for git fetch followed by
git merge FETCH_HEAD.
More precisely, git pull runs git fetch with the given parameters and
calls git merge to merge the retrieved branch heads into the current
branch. With --rebase, it runs git rebase instead of git merge.
should be the name of a remote repository as passed to
git-fetch1. can name an arbitrary remote ref (for example,
the name of a tag) or even a collection of refs with corresponding
remote-tracking branches (e.g., refs/heads/:refs/remotes/origin/),
but usually it is the name of a branch in the remote repository.
Default values for and are read from the
"remote" and "merge" configuration for the current branch as set by
git-branch --track.
I also create the visual below to show you how git fetch
and git pull
working together...