What is the difference between git fetch and git pull?
Both sync with remote, but handle integration differently.
git fetch
Downloads remote changes WITHOUT merging.
```bash git fetch origin
```
Safe workflow: ```bash git fetch origin git log origin/main # Review changes git diff main origin/main # Compare git merge origin/main # Merge when ready ```
git pull
Downloads AND merges automatically.
```bash git pull origin main
```
Key Differences
| Feature | fetch | pull |
|---|---|---|
| Downloads | ✅ Yes | ✅ Yes |
| Merges | ❌ No | ✅ Yes |
| Safe | ✅ Yes | ⚠️ Can conflict |
| Review first | ✅ Yes | ❌ No |
When to Use What?
Use fetch when:
- Want to review changes first
- Working on important code
- Not sure about conflicts
- Multiple branches to check
Use pull when:
- Quick updates needed
- Trust remote changes
- Solo development
- Simple workflows
Common Scenarios
Scenario 1: Check remote changes
```bash git fetch origin git log --oneline main..origin/main
```
Scenario 2: Pull with rebase
```bash git pull --rebase origin main
```
Best Practices
```bash
git fetch origin git merge origin/main
git pull origin main
git pull --rebase origin main ```
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.