How to list remote branches in git

Listing local branches in git is the default behaviour of calling git branch. There are times when you want to list remote branches as well.

To list remote branches, you can pass a flag to git branch. If you only want to list the remote branches then use git remote -r. This will list the branches available on the remote. If you instead use git branch -a, you’ll see all the branches for both your local and remote.

You can get the most complete information about local and remote branches by using git remote show. To do this, you need to name the remote you wish to query. Often this will simply be origin. For example git remote show origin will show a fair amount of information about your origin repository:

* remote origin
  Fetch URL: <url>
  Push  URL: <url>
  HEAD branch: main
  Remote branches:
    update-post-metadata               tracked
    clean-css                          tracked
    main                               tracked
    refs/remotes/origin/add-post-install-scheme stale (use 'git remote prune' to remove)
  Local branch configured for 'git pull':
    main merges with remote main
  Local ref configured for 'git push':
    main pushes to main (up to date)

Here you can see more detailed information about the various branches both local and remote.

← Previous Next →