git pull — Getting Updates
The git pull command downloads changes from a remote and merges them into your current branch. It's essentially git fetch + git merge in one step.
Basic Usage
git pull origin main
What Pull Does
- Fetch: Download new commits from the remote
- Merge: Integrate the remote changes into your local branch
Before pull:
local: A --- B --- C (main)
remote: A --- B --- D (origin/main)
After pull (merge):
local: A --- B --- C --- M (main)
\ /
--- D ---
git fetch vs git pull
git fetch— Downloads changes but does NOT merge. Safer — you can review first.git pull— Downloads AND merges. Convenient for simple cases.
Try it!
Simulate getting updates from a teammate:
- Check current state:
git log --oneline - Pull the latest changes:
git pull origin main - See the new commits:
git log --oneline - Check the files:
ls
Best Practices
- Pull before push — Always pull to get the latest changes before pushing your own
- Use fetch when unsure —
git fetch+ review +git mergegives you more control - Pull with rebase —
git pull --rebasekeeps a linear history (avoids merge commits)