To understand the differences, we first need to understand git’s architecture, which is a distributed version management system. Git fetch and Git pull are not only involved in git fetch and Git pull, but also helpful in understanding the whole picture. As follows:

The figure above shows git’s overall architecture and the major commands associated with each part. Let me explain the parts involved.

A working directory, in short, is the area where you work. In the case of Git, this is the local working directory of git. The contents of the workspace will contain the content submitted to the staging area and the repository (the current commit point), as well as its own modifications.

Stage area (also called index area) is a very important concept in Git. Is a transitional phase before we commit the changes to the repository. GIT’s help guide usually uses index to indicate the staging area. In your working directory there is a.git directory with an index file that stores the contents of the staging area. The git add command adds the workspace contents to the staging area.

A local repository is a repository of a version control system that exists locally. When the git commit command is executed, the staging contents are committed to the repository. Under the workspace there is a.git directory, the contents of this directory do not belong to the workspace, which is the repository data information, temporary storage related content is also in it. It is also possible to merge remote warehouse copies into local warehouses using merge or rebase. The figure only shows merge, but note that rebase can also be used here.

Remote Repository is the same concept as a local repository, except that one exists remotely and can be used for remote collaboration, while the other exists locally. Local and remote interaction can be realized through push/pull.

Remote repository copy, which can be understood as a remote repository cache that exists locally. You can run the git fetch/pull command to obtain the contents of the remote repository. Git Merge Is used to merge a remote repository copy with a local repository. In this case, git merge is used to merge a remote repository copy with a local repository. Depending on the configuration, git pull can be git fetch + git merge or git fetch + git rebase

Simply put,git Fetch does not change the code of the local repository. It just pulls the remote commit data and updates the commit ID of the remote repository to Latest.

Git /refs contains three folders: heads, remotes, tags. Heads and REMOtes record the latest COMMIT IDS for different local and remote repositories, respectively