in Technology by

 How will you differentiate between git pull and git fetch?

Please log in or register to answer this question.

1 Answer

0 votes

 Git pull command pulls all new commits from a specific branch in the central repository and makes the target branch in your local repository up-to-date.

Git fetch also aims at the same thing, however, its underlying functionality is a bit different. When you do a git fetch, all the new commits from a specific branch will be pulled in your central repository and these changes will be stored in a new branch in your local repository. This is called a fetched branch.

If you wish to see these changes in your target branch, then you need to perform a git merge after git fetch. The target branch will be updated with the latest changes only after merging it with the fetched branch.

So, a git pull brings the local branch up-to-date with its remote version, whereas a git fetch does not directly change your own local branch or working copy under refs/heads. Git fetch can be used to update your remote-tracking branches under refs/remotes/<remote>/.

In simple words, git pull is equal to git fetch followed by a git merge.

Related questions

0 votes
asked Nov 4, 2020 in Technology by JackTerrance
0 votes
asked Apr 26, 2022 in Education by JackTerrance
0 votes
asked Nov 26, 2021 in Education by JackTerrance