When working with Git, we will often use the “git fetch” và “git pull” commands khổng lồ update data from the Git remote repository to 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 fetch là gì

The comm& that we usually use with “git fetch” is “git fetch origin”. Using this commvà, you can update the lathử nghiệm 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 the Git local repository, not like the “git fetch” command, only update the metadata, not update the source code.

Xem thêm: Phố Cổ Hội An Tiếng Anh Là Gì, Những Điều Cần Biết Về Khu Phố Đáng Sống Này

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 to choose to lớn merge.

Xem thêm: Chill Là Gì, Nhạc Chill Là Gì ? Chill Mang Ý Nghĩa Như Thế Nào? Chill La Gi

For everyone lớn see this difference, I will 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 command “git pull origin master”, then “git checkout test-git” khổng lồ switch khổng lồ the test-git branch that I just created above sầu, you will see the error as follows:


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

Chuyên mục: KHÁI NIỆM LÀ GÌ
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 *