Bird
Raised Fist0
Gitdevops~20 mins

Fetch vs pull difference in Git - Practice Questions

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Git Fetch vs Pull Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Difference between git fetch and git pull

Which statement best describes the difference between git fetch and git pull?

A<code>git fetch</code> downloads changes from the remote repository but does not merge them automatically; <code>git pull</code> downloads and merges changes into the current branch.
B<code>git fetch</code> deletes local branches that are not on the remote; <code>git pull</code> only updates the remote branches.
C<code>git fetch</code> merges changes automatically; <code>git pull</code> only downloads changes without merging.
D<code>git fetch</code> pushes local changes to the remote repository; <code>git pull</code> pulls changes from other developers.
Attempts:
2 left
💡 Hint

Think about whether the command updates your working files immediately or just updates remote tracking information.

💻 Command Output
intermediate
1:30remaining
Output after git fetch

You run git fetch origin on your local repository. What is the immediate effect on your local branches?

ALocal branches are automatically merged with origin branches.
BLocal branches are reset to match origin branches.
CLocal branches are deleted if they differ from origin branches.
DLocal branches remain unchanged; remote tracking branches are updated with the latest commits from origin.
Attempts:
2 left
💡 Hint

Consider if your working files or local branches change immediately after fetching.

🔀 Workflow
advanced
2:00remaining
Choosing between git fetch and git pull in a team workflow

In a team project, you want to review changes from others before merging them into your branch. Which command should you use and why?

AUse <code>git fetch</code> to download changes first, then review and merge manually to avoid unexpected conflicts.
BUse <code>git pull</code> directly to automatically merge changes and save time.
CUse <code>git push</code> to update your branch with others' changes.
DUse <code>git clone</code> to get the latest changes from the remote repository.
Attempts:
2 left
💡 Hint

Think about how to avoid automatic merges that might cause conflicts without your knowledge.

Troubleshoot
advanced
2:00remaining
Resolving unexpected merge conflicts after git pull

You ran git pull and got merge conflicts you did not expect. What is the most likely cause?

AYour local repository is not connected to any remote repository.
BYou forgot to run <code>git fetch</code> before <code>git pull</code>.
CLocal changes conflicted with remote changes because <code>git pull</code> merged automatically without prior review.
DThe remote repository was empty, so no changes were pulled.
Attempts:
2 left
💡 Hint

Think about what happens when you merge changes automatically without checking first.

Best Practice
expert
2:30remaining
Best practice for updating local branches safely

Which practice is best to keep your local branches updated safely without losing work?

AAlways run <code>git pull --rebase</code> without checking to keep history linear.
BRun <code>git fetch</code> regularly, review remote changes, then merge or rebase manually to control integration.
CDelete local branches before pulling to avoid conflicts.
DUse <code>git push --force</code> to overwrite remote branches with local changes.
Attempts:
2 left
💡 Hint

Consider how to avoid losing work and how to review changes before merging.

Practice

(1/5)
1. What is the main difference between git fetch and git pull?
easy
A. git fetch deletes local changes; git pull only downloads updates.
B. git fetch downloads updates without changing files; git pull downloads and merges updates.
C. git fetch merges changes automatically; git pull only downloads updates.
D. git fetch uploads changes; git pull downloads changes.

Solution

  1. Step 1: Understand git fetch behavior

    git fetch downloads updates from the remote repository but does not change your working files or current branch.
  2. Step 2: Understand git pull behavior

    git pull downloads updates and immediately merges them into your current branch, changing your files.
  3. Final Answer:

    git fetch downloads updates without changing files; git pull downloads and merges updates. -> Option B
  4. Quick Check:

    Fetch = download only, Pull = download + merge [OK]
Hint: Fetch only downloads; pull downloads and merges [OK]
Common Mistakes:
  • Thinking fetch changes files immediately
  • Confusing pull as only download
  • Believing fetch uploads changes
2. Which of the following is the correct syntax to fetch updates from the remote repository?
easy
A. git merge origin/main
B. git pull origin main
C. git push origin main
D. git fetch origin

Solution

  1. Step 1: Identify fetch command syntax

    The correct command to download updates without merging is git fetch origin, where origin is the remote name.
  2. Step 2: Check other options

    git pull origin main downloads and merges; git push uploads changes; git merge merges branches locally.
  3. Final Answer:

    git fetch origin -> Option D
  4. Quick Check:

    Fetch syntax = git fetch [remote] [OK]
Hint: Fetch uses 'git fetch' plus remote name [OK]
Common Mistakes:
  • Using git pull instead of fetch
  • Confusing push with fetch
  • Trying to merge with fetch command
3. You run git fetch followed by git status. What will git status show regarding your branch?
medium
A. Your branch is behind 'origin/main' by some commits.
B. Your branch is up to date with 'origin/main'.
C. Your branch has uncommitted changes.
D. Your branch is ahead of 'origin/main' by some commits.

Solution

  1. Step 1: Understand effect of git fetch on local branch

    git fetch updates remote tracking branches but does not merge changes into your current branch.
  2. Step 2: Interpret git status after fetch

    If remote has new commits, git status will say your branch is behind 'origin/main' by those commits, since you haven't merged yet.
  3. Final Answer:

    Your branch is behind 'origin/main' by some commits. -> Option A
  4. Quick Check:

    Fetch updates remote info; status shows branch behind [OK]
Hint: Fetch updates remote info; status shows if behind [OK]
Common Mistakes:
  • Assuming fetch merges changes automatically
  • Thinking status shows branch up to date after fetch
  • Confusing uncommitted changes with remote updates
4. You ran git pull but got a merge conflict error. What should you do to fix this?
medium
A. Manually resolve conflicts in files, then commit the merge.
B. Delete the repository and clone again.
C. Run git reset --hard to discard local changes.
D. Run git fetch again to fix conflicts.

Solution

  1. Step 1: Understand merge conflict after git pull

    git pull merges remote changes into your branch; conflicts happen if changes clash.
  2. Step 2: Resolve conflicts properly

    You must open conflicted files, fix conflicts manually, then stage and commit the merge to complete it.
  3. Final Answer:

    Manually resolve conflicts in files, then commit the merge. -> Option A
  4. Quick Check:

    Fix conflicts manually, then commit merge [OK]
Hint: Resolve conflicts manually, then commit [OK]
Common Mistakes:
  • Rerunning fetch to fix conflicts
  • Resetting hard loses local work
  • Deleting repo is unnecessary
5. You want to review remote changes before merging them into your current branch. Which sequence of commands should you use?
hard
A. git pull then git log
B. git merge origin/main then git fetch
C. git fetch then git diff origin/main
D. git push then git pull

Solution

  1. Step 1: Fetch remote changes without merging

    Use git fetch to download remote updates without changing your files.
  2. Step 2: Review differences before merging

    Use git diff origin/main to see changes between your branch and remote branch before merging.
  3. Final Answer:

    git fetch then git diff origin/main -> Option C
  4. Quick Check:

    Fetch to download, diff to review before merge [OK]
Hint: Fetch first, then diff to review changes [OK]
Common Mistakes:
  • Pull merges immediately without review
  • Merging before fetching misses updates
  • Push uploads changes, not for review