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

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!