Git List Branches: Learn to View Local & Remote Branches Easily!

Git List Branches

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

If you are a developer maintaining feature updates or a member of a DevOps team managing releases, you should know how to git list branches. But because of how every Git repo is created — from branching — Git is an excellent version control system. If you are not aware of what branches exist — locally and in remote — you are susceptible to confusion, mistakes, or work duplication.

Just imagine pulling from a repo and making changes to a branch that’s already given and not noticing the MP branch that breaks it because you did not see what’s already implemented. Or not seeing some code being merged due to the branch being out of sight. These are common situations if you don’t know how to list branches in git style.

In this complete tutorial, we’ll teach you about git list branches.

Understanding Git List Branches

Git commands are used to view branches in a Git repository. While there is no single command named git list branches, several Git commands can be used for displaying:

  • Local branches: the branches that exist on your local machine
  • Remote branches: the branches are tracked from a remote repo like origin
  • Merged and unmerged branches: assist with cleanup, workflow organization

With knowledge of these commands, you can easily move between features, bug fixes, staging environments, and production-ready code.

Requirements to List Git Branches

Before running any commands with Git, ensure that the following is set up:

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

Git Installed

Check if Git is installed:

git --version

To install Git, use these commands:

sudo apt install git         # For Debian/Ubuntu
brew install git             # For macOS

Git Repository Initialized or Cloned

You can create a new repository:

mkdir sample-repo && cd sample-repo
git init

Or clone an existing one:

git clone https://github.com/example/repo.git
cd repo

Fetch All Remote Data

Make sure you have the latest from the remote:

git fetch --all

List Git Branches: 6 Methods

Now, we are all set. Let’s dive into the methods to List Git Branches:

Method 1: List Local Branches in Git

List local branches on your system:

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

git branch

Output:

* main
  dev
  feature-login

In this case, * means your current branch. Use this very information to track your workspace.

Method 2: Git List All Branches (Local + Remote)

To include local as well as remote branches:

git branch -a

Output:

* main
  dev
  feature-login
  remotes/origin/main
  remotes/origin/feature-logout

This command is important when you want to see all activity across branches.

Method 3: Git List Remote Branches

To only see remote branches:

git branch -r

Output:

 origin/main
  origin/dev
  origin/feature-logout

This gives you some basic context on what your team has pushed to the central repository.

Method 4: Using Git Show Branch List with Last Commits

To view each branch with its latest commit info:

git branch -v

Output:

* main               923d9fc Updated dependencies
  dev                d1a64ff Added login component
  feature-payment    7c2d511 Added payment gateway

This lists commit hashes and messages. Perfect for a quick progress review.

Method 5: Git List Merged and Unmerged Branches

To show branches that have been merged to the current one:

git branch --merged

Output:

  main
  fix-header

To display branches that have yet to be merged:

git branch --no-merged

Output:

  dev
  feature-billing

They help clean stale branches or detect pending work.

Method 6: List Branches Without Cloning

List remote repo branches without clone:

git ls-remote --heads https://github.com/example/repo.git

Output:

3c3f3f9a1c02c refs/heads/main
9a0d9fa1dffa2 refs/heads/dev

Great for the inspection of remote repos.

Git Branch Management and the Role of CyberPanel

CyberPanel

Git Workflows made easy with CyberPanel’s visual Git Manager. As a robust web hosting control panel, here is its role in Git branch management:

  • The GUI for Branch Control: List, switch, and deploy branches without the CLI
  • Automated Deployment: Push into Github, and automated deployment is on the server.
  • Webhook Integrations: Automatic Syncing of Repositories
  • Branch Selection for Deployment: The branch you would like to deploy to staging or production.

CyberPanel integrates this functionality around basic branches at a high level, making it easy and powerful for the end users.

FAQs Around Git List Branches

1. How to list all branches (local and remote) in Git?

Run git branch -a to list all the branches.

2. How to see local branches with the latest commits?

Use git branch -v for branch names with commit summaries.

3. Is it possible to list branches from a repo without cloning?

Use git ls-remote –heads  to see remote branches.

Final Thoughts!

Whether we are working solo or on larger team-based projects, using local and remote branches keeps our code base relatively clean and makes overall development a lot faster.

Want the Git experience that is truly seamless? CyberPanel takes it with in-browser Git control using live commands. No need to switch between terminal and server.

Try Git Integration With CyberPanel Now!

Hasib Iftikhar
I'm Hasib Iftikhar, a dedicated technical writer at CyberPanel, joining the team in July 2024. With three years of extensive experience in content writing, I specialize in copywriting, article writing, guest posting, affiliate content writing, and SEO. My expertise ensures that each piece of content I create is engaging, informative, and optimized for search engines, helping businesses enhance their online presence and reach their target audience effectively.
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!