When working with Git, we will often use the “git fetch” and “git pull” commands to lớn update data from the Git remote repository to lớn the Git local repository. So what’s the difference between these two commands is, let’s find out in this tutorial!

First, I’ll talk about “git fetch” first.

Bạn đang xem: Git pull là gì? khác gì với git fetch

The command that we usually use with “git fetch” is “git fetch origin”. Using this commvà, you can update the lademo information from Git remote repository. But the information here does not mean that the entire data from the Git remote repository, it’s just the metadata information. For example, which branches our Git remote repository has, there are any changes from the Git remote repository that we have not updated yet? It only updates that information, not making changes, synchronizing Git local repository with Git remote repository.

What about “git pull”?

We often use the “git pull origin ” comm& to lớn update source code changes in the branch we are working on. It will update all those changes to lớn the Git local repository, not lượt thích the “git fetch” command, only update the metadata, not update the source code.

Xem thêm: Đối Soát Tiếng Anh Là Gì ? Các Khái Niệm Liên Quan Tới Công Nợ

Because of that, using “git pull”, we often encounter a problem called source code conflict. The reason is because the code we changed in the Git local repository, someone also changed on the Git remote repository, updated that code, Git does not know which code khổng lồ choose lớn merge.

Xem thêm: Quyết Định Cử Đi Công Tác Tiếng Anh Là Gì, Quyết Định Cử Đi Công Tác Bằng Tiếng Anh

For everyone lớn see this difference, I will bởi vì an example as follows:

I have sầu a repository named “test” on Bitbucket as follows.

*

On my machine:

*

Now suppose I create a new test-git branch on Bitbucket:

*

Then use the commvà “git pull origin master”, then “git checkout test-git” lớn switch to the test-git branch that I just created above, you will see the error as follows:

*

However, if you use the commvà “git fetch origin” & “git checkout test-git”, you will see the results as follows:


Chuyên mục: Ý NGHĨA
Bài viết liên quan

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *