Git Pull
Last updated
git pull updates your current branch with the latest commits from its remote. Under the hood it runs git fetch to download the changes, then git merge to integrate them - so git pull = git fetch + git merge. Add --rebase to replay your local commits on top instead of creating a merge commit.
Try these in the terminal playground - a real shell in your browser, nothing to install.
Syntax
| Command | What it does |
|---|---|
git pull | Fetch and merge the current branch's remote |
git pull origin main | Pull a specific branch from a remote |
git pull --rebase | Fetch, then rebase your commits on top |
git pull --ff-only | Only pull if it can fast-forward (no merge) |
git pull --no-rebase | Force a merge even if rebase is the default |
Common cases
| Goal | Command |
|---|---|
| Get the latest on your branch | git pull |
| Keep history linear | git pull --rebase |
| Abort a pull that hit conflicts | git merge --abort |
| Discard local commits and match remote | git fetch then git reset --hard origin/main |
Git pull FAQ
What does git pull actually do?
It downloads the latest commits from the remote for your current branch and integrates them into your local branch. It's shorthand for two commands:
git fetch (download) followed by git merge (integrate). If you configure it, the merge step becomes a rebase instead.What's the difference between git pull and git fetch?
git fetch only downloads remote changes and updates your remote-tracking branches - it doesn't touch your working branch. git pull does that fetch and then merges the changes into your current branch. Use fetch to review incoming changes first; use pull to grab and integrate them in one step.What is git pull --rebase and when should I use it?
git pull --rebase fetches remote commits and then replays your local commits on top of them, instead of creating a merge commit. It keeps history linear, which many teams prefer. Use it when you have local commits that haven't been pushed and you want to avoid a merge commit every time you pull.How do I fix conflicts after a git pull?
A pull can raise merge conflicts when local and remote changes overlap. Open the conflicted files, resolve the marked sections, then
git add them and git commit (for a merge) or git rebase --continue (for a rebase pull). If you'd rather back out, run git merge --abort or git rebase --abort.Can I practice this online?
Yes. Open the terminal playground to run
git pull in a real shell in your browser - nothing to install. Coddy's free interactive Git course also covers working with remotes step by step.