How do I get a list of all branches in Git?


You simply need to make use of the git branch command on your Terminal/Console.


List local branches:

    Example:
    git branch
    
      branch-new-123
      main
      release
      staging
      ticket-2023
    * ticket-2023-07
      ticket-2023-08

    As you can see, after running the git branch on Terminal I got the list of all branches that I have locally.

    Git - Get List of Local Branches

    Note: The branch that has an * mark before indicates the current branch.


List remote (origin) branches as well:

    If you want to display remote branches as well, add a --all flag

    Example:
    git branch --all

Using the --list flag

    If you want to get a list of branches based on a pattern match, make use of the --list flag.

    Example:
    % git branch --list 'ticket*'
      ticket-2023
    * ticket-2023-07
      ticket-2023-08
    Git - Let a list of branches using --list flag

Offical Git Documenation on Branching:


- https://git-scm.com/docs/git-branch

-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X





























Copyright ยฉ Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap