The difference between git pull and git fetch

Source: Internet
Author: User

See a lot of different things about git fetch and git pull from Baidu

Practice:

Create a new project from GitHub try,copy to Local.

Modify the Readme.txt file on the GitHub website and add a new "alter README"

In the local warehouse Readme.txt also added a new sentence, "Add some thing"

It is not possible to commit the local code to GitHub now. An error message will appear!!!

You should download the code from the remote repository first

(1) What happens with git pull?

Git pull Origin Master


Open the Readme.txt file for the local warehouse

gitPull: the equivalent of getting the latest version from remote and merge to local


(2) using the git fetch command

Next up, we've changed the code of the conflict and submitted it.

Add use fetch on the Readme.txt file

Readme.txt file modification in the local repository, add use Fetch Loca

L


Submit the code locally and submit the code, as shown above, cannot be submitted up

Input

Git fetch Origin Master



Open a Readme.txt file without any changes

We re-enter

Git log-p master: Origin/master

You can see who has changed the code in the remote repository, and how to modify it

And then enter

git merge Origin/master

Manual Merge Warehouse

Then let's take a look at the Readme.txt file

Fetch is equivalent to getting the code modified on the GitHub remote repository,

You can log-p master via git. Origin/master to see the different

Finally, merge the code according to your needs


Conclusion: Pull is equivalent to a fetch operation plus a merge operation.

But fetch better, you can check the update before merging.



The difference between git pull and git fetch

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.