Git obtains the branch of the latest version from the remote to the local using two commands:
git fetch: Git is going to get the latest version from remote to local, but it do not automatically merge.
git fetch origin master
git log -p master..origin/master
git merge origin/master
The commands above mean that download latest version of the main branch from origin from the remote to origin master branch. And then compares the local master branch and origin master branch. Finally, merge.
git pull: Git is going to get the latest version from the remote and merge into the local.
git pull origin master
The command above is the equivalent to git fetch
and git merge
. In practice, git fetch
maybe more secure because before the merge we can see the changes and decide whether to merge.