Git: Pull a Remote Branch
Last updated
To pull changes from a specific remote branch, name the remote and branch: git pull origin <branch>. This fetches that branch and merges it into your current one. If you want the remote branch as its own local branch, fetch first and check it out - see the examples below.
Try these in the terminal playground - a real shell in your browser, nothing to install.
Syntax
| Command | What it does |
|---|---|
git pull origin main | Pull main from origin into the current branch |
git pull origin feature --rebase | Pull a branch and rebase instead of merge |
git fetch origin | Download all remote branches (no merge) |
git switch feature | Check out a fetched remote branch locally |
Pull a branch you don't have locally
Fetch it, then create a local branch that tracks it.
| Step | Command | Result |
|---|---|---|
| 1 | git fetch origin | Download the remote's branches |
| 2 | git switch feature | Create a local feature tracking origin/feature |
| 3 | git pull | Now a plain pull keeps it up to date |
Git pull remote branch FAQ
How do I pull a specific remote branch?
Run
git pull origin <branch>. This fetches the named branch from the origin remote and merges it into whatever branch you currently have checked out. To pull it into a matching local branch instead, switch to that branch first, then run git pull.How do I pull a remote branch that I don't have locally?
Run
git fetch origin to download the remote's branches, then git switch <branch> - modern Git automatically creates a local branch tracking origin/<branch>. After that, a plain git pull keeps it up to date.What's the difference between pulling into the current branch and a new one?
git pull origin <branch> merges the remote branch into your current branch, mixing their histories - useful for bringing changes in. If you instead want the remote branch on its own, fetch and switch to it so it becomes a separate local branch that tracks the remote.How do I pull with rebase instead of merge?
Add
--rebase: git pull origin <branch> --rebase fetches the branch and replays your local commits on top of it, keeping history linear instead of creating a merge commit.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.