Working with Git involves managing code across multiple branches and often multiple collaborators. One important task is checking remote branches — those that exist on the repository hosted on platforms like GitHub, GitLab, or Bitbucket.
In this article, you’ll learn how to view, fetch, and inspect remote branches in Git, whether you’re tracking changes, reviewing team progress, or pulling code to your local machine.
🌐 What Is a Remote Branch?
A remote branch is a branch that exists on a remote repository. You don’t work on it directly; instead, you fetch it, track it, and merge it into your local branches as needed.
🔍 How to View Remote Branches
To list all remote branches, run:
git branch -r
Example Output:
origin/main
origin/feature/login
origin/bugfix/payment-timeout
This lists all branches on the origin
remote (or others, if configured).
🔄 Fetch Remote Branch Updates
To make sure your list of remote branches is up to date:
git fetch
Or to fetch from all remotes:
git fetch --all
This downloads updated references of all remote branches without merging them into your local branches.
👀 Check Out a Remote Branch Locally
To inspect or work with a remote branch, first check it out locally:
git checkout -b feature/login origin/feature/login
This creates a local branch feature/login
tracking origin/feature/login
.
Alternatively, with newer Git versions:
git switch --track origin/feature/login
📋 View All Local and Remote Branches
To get a complete list of both local and remote branches:
git branch -a
This will show:
* main
remotes/origin/main
remotes/origin/feature/login
✅ Summary of Commands
Command | Purpose |
---|---|
git branch -r | List remote branches |
git fetch | Update info about remote branches |
git checkout -b <branch> origin/<branch> | Create a local branch tracking a remote one |
git branch -a | List all branches (local and remote) |
Conclusion
Remote branches are essential for distributed teamwork and version control. By knowing how to check, track, and inspect them, you can ensure a smoother development process and collaborate more effectively.