How to pull remote branch from somebody else's repo
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
To pull a branch from somebody else’s repository, you usually add their repository as another Git remote, fetch from it, and then create a local branch that tracks the fetched branch. The key idea is that Git branches live under remotes, so you do not “pull from a person” directly. You fetch from a named remote and then check out the branch you want.
Add the Other Repository as a Remote
Suppose your main repository already has origin, and you want to access a collaborator’s fork.
Now Git knows about another source of branches called alice.
This does not change your current branch or your main remote. It only tells Git where else it can fetch from.
Fetch the Remote Branches
After adding the remote, fetch its refs:
Now you can inspect the branches available from that remote:
You should see names such as:
Check Out a Local Branch That Tracks It
If you want to work on alice/feature-x, create a local branch from it:
Or with newer switch syntax:
Now you have a local branch based on the other person’s remote branch.
Pull Later Updates from That Same Remote Branch
Once your local branch tracks the remote branch, you can update it by pulling from the specific remote:
Or, if your branch tracking is configured correctly, plain git pull may be enough while you are on that branch.
Being explicit is safer when multiple remotes are involved.
Fetch Without Adding a Permanent Remote
If you only need the branch once, you can fetch it directly by URL:
This is useful for one-off review work, but if you expect repeated collaboration, a named remote is cleaner.
Understand the Difference Between fetch and pull
git fetch downloads refs without merging them into your current branch.
git pull is roughly:
- fetch
- merge or rebase into the current branch
When working with somebody else’s repository, starting with fetch is often safer because it lets you inspect the branch before integrating anything into your current work.
If the Repository Is a Fork
A common setup is:
- '
origin= your fork' - '
upstream= original repository' - '
alice= collaborator fork'
That is perfectly valid. Git can work with as many remotes as you need, as long as you keep the names clear and avoid assuming everything comes from origin.
Verify Before Merging
After checking out the collaborator branch, inspect the history:
This matters because it tells you whether the branch is based on the expected mainline, whether it is stale, and whether merging it into your own branch will be straightforward.
Remove the Remote If It Was Temporary
If you only needed the collaborator remote briefly, remove it when you are done:
That keeps the repository configuration tidy and avoids clutter in tools that show all remotes and remote branches.
Common Pitfalls
The biggest mistake is confusing a remote branch name such as alice/feature-x with a local branch. Another is using git pull too early instead of fetching and inspecting first. Developers also sometimes create a local branch but forget which remote it tracks, which leads to later pulls going to the wrong place. Finally, if the collaborator repository is private, authentication and access must be working before any fetch or pull command will succeed.
Summary
- Add the other repository as a Git remote.
- Fetch its branches before trying to check one out.
- Create a local branch that tracks the collaborator’s remote branch.
- Prefer
fetchfirst and inspect before merging or rebasing. - Remove temporary remotes when they are no longer needed.

