git pull Command Guide
Fetch from and integrate with another repository or a local branch
Dai Aoki
CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm
Quick Reference
Basic
git pullPull from tracked remotegit pull origin mainPull specific branchgit pull --allPull all remotesStrategy
--rebaseRebase instead of merge--no-rebaseForce merge--ff-onlyFast-forward onlyOptions
--autostashStash changes automatically--no-commitDon't auto-commit merge-vVerbose outputDownloadable Image Preview
Basic Usage
The git pull command fetches changes from a remote repository and integrates them into your current branch. It's a combination of git fetch and git merge.
# Pull from tracked remote branch
git pull
# Pull from specific remote and branch
git pull origin main
# Pull from all configured remotes
git pull --allPull vs Fetch
Understanding when to use each:
# Fetch + Merge (what pull does)
git fetch origin
git merge origin/main
# Equivalent single command
git pull origin main
# Safer approach: fetch first, review, then merge
git fetch origin
git log HEAD..origin/main # See what's new
git merge origin/mainCommon Options
| Option | Description |
|---|---|
| --rebase | Rebase instead of merge |
| --no-rebase | Force merge (override config) |
| --ff-only | Only allow fast-forward merges |
| --autostash | Automatically stash/unstash changes |
| --no-commit | Don't automatically commit the merge |
| -v, --verbose | Show more output details |
Pull with Rebase
Using rebase keeps your history linear and clean:
# Pull and rebase your commits on top
git pull --rebase origin main
# Configure pull to always rebase
git config --global pull.rebase true
# One-time merge even with rebase config
git pull --no-rebasegit config --global pull.rebase true for cleaner history. Your local commits will be replayed on top of remote changes.Handling Conflicts
# When conflicts occur during pull
git pull origin main
# CONFLICT (content): Merge conflict in file.js
# View conflicted files
git status
# Edit files to resolve conflicts (remove <<<<<<< markers)
# Then mark as resolved
git add file.js
# Complete the merge
git commit
# Or abort and try again
git merge --abortPractical Examples
# Daily workflow
git pull
# ... make changes ...
git add .
git commit -m "My changes"
git push
# Pull with automatic stash
git pull --autostash
# Pull only if fast-forward possible
git pull --ff-only
# Pull and rebase for clean history
git pull --rebase
# Undo a pull
git reset --hard ORIG_HEAD
# See what you're about to pull
git fetch origin
git log HEAD..origin/mainFrequently Asked Questions
What is the difference between git pull and git fetch?
"git fetch" downloads changes but doesn't integrate them. "git pull" is essentially "git fetch" followed by "git merge" (or rebase). Fetch is safer as it lets you review changes before integrating.
Should I use git pull --rebase?
Using --rebase creates a cleaner linear history by replaying your commits on top of the remote changes. It's preferred for feature branches but avoid it on shared branches if you've already pushed.
What happens if I have uncommitted changes when I pull?
Git will refuse to pull if your changes would be overwritten. Either commit your changes, stash them (git stash), or use "git pull --autostash" to automatically stash and restore them.
How do I resolve merge conflicts after a pull?
Edit the conflicted files to resolve the conflicts (look for <<<<<<< markers), then "git add" the resolved files and "git commit" to complete the merge. Or use "git mergetool" for a visual tool.
How do I undo a git pull?
Use "git reset --hard ORIG_HEAD" to undo the last pull. Git stores the previous HEAD position before operations like pull and merge. Check "git reflog" to find the exact commit to reset to.
Summary
git pull keeps your local branch up to date with the remote. Consider using --rebase for cleaner history and --autostash for convenience.
Quick Reference
git pull- Pull from tracked remotegit pull --rebase- Pull and rebasegit pull --autostash- Auto-stash changesgit pull --ff-only- Fast-forward only
Official Documentation
For authoritative information, refer to the official documentation: