Difference between git fetch and git pull

Source: Internet
Author: User

Original article: http://www.tech126.com/git-fetch-pull/

Git obtains the latest version from a remote Branch to a local machine with the following two commands:
1. Git
Fetch: equivalent to obtaining the latest version from a remote device to a local device.

    
git fetch origin master
git log -p master..origin/master
git merge origin/master

Meaning of the preceding command:
First, download the latest version from the master branch of the remote origin to the origin/Master branch.
Then compare the differences between the local master Branch and the origin/Master Branch
Merge at last
The above process can be implemented in the following clearer ways:

git fetch origin master:tmp
git diff tmp 
git merge tmp

Remotely obtain the latest version to the local test Branch
And then compare and merge
2. Git
Pull: equivalent to remotely obtaining the latest version and merge to the local device.

git pull origin master

The above commands are actually equivalent to git fetch and git merge
In practice, git fetch is safer
Because before merge, we can check the Update Status and then decide whether to end the merge.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.