0 votes
in Git by (30.8k points)
Explain difference between "git pull" and "git fetch"?

1 Answer

0 votes
by (6.0k points)

$ git pull origin master

git pull says "bring the changes in the remote repository to where I keep my own code."

Normally git pull does this by doing a git fetch to bring the local copy of the remote repository up to date, and then merging the changes into your own code repository and possibly your working copy. If you don’t closely manage your branches, you may run into frequent conflicts.


$ git fetch origin

git fetch is the command that says "bring my local copy of the remote repository up to date."

When you command fetch, Git extract all commits from the target branch that does not exist in the current branch and keeps them in your local repo. But, it does not merge them with your current branch. This is mostly useful if you need to keep your repo up to date, but are working on some solution that might break if you update your files. To integrate the commits into your master branch, we use merge.

Related questions