Git 2 reference · Remotes

git fetch and git pull Command (Git)

Download new commits from a remote (fetch), or download and integrate them into your branch (pull).

Git 2

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git fetch [REMOTE]   git pull [--rebase|--ff-only]

Parameters

ParameterDescription
fetch --prune Also delete local references to removed remote branches.
pull --rebase Rebase your commits on top of the remote's.
pull --ff-only Refuse if a merge would be needed.

Examples

Fetch, then pull
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
cd ..; git clone -q app teammate
cd app; echo new > feature.txt; git add .; git commit -q -m 'Add feature'
cd ../teammate; git fetch -q
git status -sb | head -1
git pull -q --ff-only; git log --oneline | head -1

Output

## main...origin/main [behind 1]
2bba6e6 Add feature

Run this on your computer — see “Get Started” for setup.

pull --rebase keeps history linear
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
cd ..; git clone -q app mine
cd app; echo a > a.txt; git add .; git commit -q -m 'Remote work'
cd ../mine; echo b > b.txt; git add .; git commit -q -m 'Local work'
git pull -q --rebase
git log --oneline

Output

b89745d Local work
be42a69 Remote work
7f7f133 Initial commit

Run this on your computer — see “Get Started” for setup.

Was this page helpful?