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 Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

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