AlgoMaster Logo

Listing Branches

Last Updated: January 3, 2026

5 min read

Branches allow you to work on different features or fixes in parallel without impacting the main codebase. Whether you're managing a solo project or collaborating with a team, knowing how to view your branches helps you maintain clarity in your workflow

This chapter dives deep into the various ways you can list branches, the details behind those commands, and common scenarios where they can be useful.

Basic Branch Listing

The simplest way to view all the branches in your repository is with the git branch command. By default, this command lists all the local branches in your current repository.

When you run this command, you will see output similar to the following:

The asterisk (*) indicates the branch you are currently on. This visual cue is essential for understanding your current context within the repository.

Listing Remote Branches

In addition to local branches, Git allows you to track remote branches as well. To see the branches that exist on your remote repository, use the -r flag with the git branch command.

The output will look something like this:

Here, the origin/ prefix indicates that these branches exist on the remote repository named "origin." Understanding remote branches is particularly important when collaborating with others, as it helps you see what branches are available for pulling or merging.

Listing All Branches

If you want a comprehensive view that includes both local and remote branches, you can combine the two with the -a flag:

This command will yield output similar to:

This view is particularly helpful in larger projects where multiple branches exist both locally and remotely, allowing you to see everything at a glance.

Filtering and Sorting Branches

As projects grow, the number of branches can quickly become unmanageable. Fortunately, Git provides options to filter and sort branches, making it easier to find what you need.

Filtering Branches by Name

If you're looking for a branch that matches a specific pattern, you can use the --list option with a wildcard:

This command will return all branches beginning with feature/, helping you focus on specific features without sifting through unrelated branches.

Sorting Branches

While Git does not offer built-in sorting options for branches, you can pipe the output into Unix commands for sorting. For example:

This command sorts your branches in alphanumeric order, which can help you quickly locate a branch by name.

Visualizing Branches

Sometimes, visualizing branches can provide clarity that a text list cannot. Git offers a way to visualize branches using git log with the --graph option. This command shows the commit history along with branch relationships in a graphical format.

The output will present a tree-like structure, showing how branches diverge and merge over time. This visualization can be particularly helpful in understanding the flow of development and identifying where branches may need to be merged or deleted.

Summary and Best Practices

Listing branches is an essential skill for any Git user. Here are some best practices to keep in mind:

  • Regularly list and review branches to stay aware of your project's state.
  • Use git branch -a to see both local and remote branches for better context.
  • Incorporate filtering and sorting commands to streamline your workflow.
  • Visualize your branches with git log --graph to grasp complex histories.
  • Clean up old branches to maintain a tidy repository.

With these tools and practices, you can navigate your Git branches confidently and efficiently.

Now that you understand how to list branches effectively, you are ready to explore the concept of the HEAD Pointer. In the next chapter, we will delve into how HEAD functions within Git, allowing you to understand your current position in the commit history and how it influences your workflow.