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
Syntax
git fetch [REMOTE] git pull [--rebase|--ff-only]
Parameters
| Parameter | Description |
|---|---|
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
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.
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.
Related
git push· Upload local commits and tags to a remote branch; -u sets the upstream, and --force-with-lease rewrites history safely.git merge· Combine another branch into the current one, fast-forwarding when possible or creating a merge commit.git rebase· Replay your branch's commits on top of another branch for a linear history, or clean up commits with -i before sharing.- Remotes: clone, fetch, pull and push · tutorial