iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

git pull

git pull is fetch + merge (or rebase). Default is merge, which makes ugly merge commits on every sync. Configure pull.rebase = true and your history stays linear.

Configure pull, autostash, ff-only

EXAMPLE
# Set rebase as the default — recommended for most workflows
git config --global pull.rebase true

# Also stash uncommitted changes around the pull
git config --global rebase.autostash true

# OR: refuse to pull unless it's a fast-forward (safest for shared branches)
git config --global pull.ff only

# Per-command override
git pull --rebase               # rebase this time
git pull --no-rebase            # merge this time
git pull --ff-only              # die if it would create a merge

# Conflict workflow with --rebase
git pull --rebase
#   → CONFLICT (content): Merge conflict in src/Checkout.tsx
$EDITOR src/Checkout.tsx        # resolve <<<<<<< / ======= / >>>>>>> markers
git add src/Checkout.tsx
git rebase --continue
# Or bail
git rebase --abort

# Common gotchas
#   1. Untracked or unstaged changes block a pull. autostash fixes this.
#   2. After a force-push upstream, pull with --rebase will fail.
#      git fetch + git reset --hard origin/main  is the recover.
#   3. Always know if it's a rebase pull (default in some teams) before
#      pushing — you don't want to push someone else's rewritten history.

Why it matters

pull.rebase = true + rebase.autostash = true is the single most quality-of-life-improving Git config most devs are missing.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
git pull               # fetch + merge
git pull --rebase      # fetch + rebase (linear history)
Try it Yourself »

Exercise

Pull with a linear history (rebase).

git pull

Discussion

Loading…