Pull Branch from GitHub
Pull Branch from GitHub: Checking Out Remote Branches Locally
When a teammate creates a branch on GitHub or pushes a new feature branch for code review, your local repository does not know about it until you fetch from origin. Pulling a remote branch brings its files and commits onto your computer so you can test or add commits.
Fetching and Switching to a New Remote Branch
First run git fetch origin to download all new branch pointers and commits from GitHub without altering your current working branch:
git fetch origin
git branch -r
When origin/feature/header-nav appears in the remote branch list, create and switch to a local tracking branch with one command:
git switch feature/header-nav
Modern Git sees that no local feature/header-nav exists yet, finds the exact match origin/feature/header-nav, creates the local branch, and sets up upstream tracking automatically.
Explicit Form When Names Differ or Multiple Remotes Exist
If you have multiple remotes (such as origin and upstream) or want a different local branch name, pass -c and specify the remote branch explicitly:
git switch -c review-header origin/feature/header-nav
Updating an Already Checked-Out Branch
Once your local tracking branch exists, pull subsequent teammate commits into it with:
git pull
Verify your branch tracking relationship anytime using git branch -vv.
Common Mistakes When Pulling Branches
Running git pull origin feature/header-nav while you are still standing on main merges the feature branch directly into main instead of checking out the feature branch separately. Always check git branch first and switch onto the target branch before pulling.
Frequently Asked Questions
Why does git switch feature/header-nav say invalid reference?
Your local repository has not fetched the remote branch pointer yet. Run git fetch origin first, then run git switch feature/header-nav.
What is the difference between git switch and git checkout --track?
git switch <branch> automatically tracks origin/<branch> when exactly one remote matches, replacing the older git checkout --track origin/<branch> syntax.
Can I pull a branch from someone else's fork without cloning again?
Yes. Add their fork as a second remote (git remote add teammate <url>), run git fetch teammate, and switch with git switch -c teammate-fix teammate/feature/header-nav.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With