What is the difference between git pull and git fetch?
Short answer: git fetch: It retrieves changes from a remote repository but does not apply them to your working directory.
Explain a bit more
You can think of it as checking for updates without actually installing them. git pull: This does two things: it fetches the latest changes and then merges them into your current branch. It's like fetching updates and immediately applying them. Real-World Example: If you're working on a project with teammates, git fetch allows you to see what changes have been made without affecting your code. git pull, on the other hand, will update your local copy and merge those changes with your work, which can sometimes result in merge conflicts.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png