fetch vs pull
- Git course
- Intermediate
- Lesson 30/82
- 4 min
Learn that fetch does not merge while pull does.
The Difference Between Fetch and Pull
git fetch downloads changes from the remote repository but does not merge them into the current working branch. git pull downloads remote changes and integrates them into the current branch.
git fetch origin
git pull origin mainUse fetch to inspect changes first, or pull to download and integrate them together.
The Integration Step of Pull
The git pull operation generally includes retrieving data from the remote repository and integrating those changes into the current branch. This integration usually happens through a merge operation.
git pull origin mainIf the remote and local histories are incompatible, a merge conflict may occur during pull. In that case, you need to resolve the conflict.
Practice Get Remote Changes with Pull
Download changes from the main branch of the origin remote and integrate them into the current branch. Then check the repository status.
Starter code
# Uzak değişiklikleri indir ve entegre et
# Durumu kontrol etSample solution
git pull origin main
git statusExpected output
On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which command downloads remote changes and integrates them into the current branch?
- git status
- git fetch
- git remote
- git pull Correct answer
Explanation: <code>git pull</code> downloads remote changes and integrates them into the current branch. Fetch only downloads remote information.
2 Integrate a Specific Remote Branch
git pull origin ____
git pull origin feature
Explanation: The command specifies the remote name first, followed by the branch to integrate. The remote is specified as origin here.
3 Fetch and Pull Comparison
| Term | Meaning |
|---|---|
git fetch |
Downloads, does not merge |
git pull |
Downloads and integrates |
merge |
Combines branches |
origin |
Remote repository label |