sync

git pull

Fetches from the remote and integrates the changes into the current branch, effectively 'git fetch' followed by 'git merge' (or rebase). Updates your working tree with upstream commits.

git pull [<remote> [<branch>]]

Common flags

Flag Purpose
--rebase Rebase local commits on top of fetched work instead of merging
--ff-only Refuse to pull unless a fast-forward is possible
--no-rebase Force a merge even if pull.rebase is configured
--autostash Stash and reapply local changes around the pull
--prune Remove remote-tracking refs that no longer exist upstream

Examples

git pull

Pull from the tracked upstream branch

git pull --rebase origin main

Rebase local commits on top of origin/main

git pull --ff-only

Only accept fast-forward updates, no merge commits

Gotcha

Default merge behavior creates unnecessary merge commits; setting 'pull.rebase = true' or using --ff-only keeps history linear.

Related commands

← All Git commands · Git cheat sheet · Git rebase vs merge