Terminal GuideTerminal Guide

git pull Command Guide

Fetch from and integrate with another repository or a local branch

6 min readLast updated: January 19, 2026
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Basic

git pullPull from tracked remote
git pull origin mainPull specific branch
git pull --allPull all remotes

Strategy

--rebaseRebase instead of merge
--no-rebaseForce merge
--ff-onlyFast-forward only

Options

--autostashStash changes automatically
--no-commitDon't auto-commit merge
-vVerbose output

Downloadable Image Preview

Failed to generate 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.

bash
# Pull from tracked remote branch
git pull

# Pull from specific remote and branch
git pull origin main

# Pull from all configured remotes
git pull --all

Pull vs Fetch

Understanding when to use each:

bash
# 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/main

Common Options

OptionDescription
--rebaseRebase instead of merge
--no-rebaseForce merge (override config)
--ff-onlyOnly allow fast-forward merges
--autostashAutomatically stash/unstash changes
--no-commitDon't automatically commit the merge
-v, --verboseShow more output details

Pull with Rebase

Using rebase keeps your history linear and clean:

bash
# 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-rebase
Tip
Configure git config --global pull.rebase true for cleaner history. Your local commits will be replayed on top of remote changes.

Handling Conflicts

bash
# 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 --abort

Practical Examples

bash
# 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/main

Frequently 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 remote
  • git pull --rebase - Pull and rebase
  • git pull --autostash - Auto-stash changes
  • git pull --ff-only - Fast-forward only

Official Documentation

For authoritative information, refer to the official documentation:

Related Articles