How do I list all remote branches in Git 1.7+?

Viewed 678489

I've tried git branch -r, but that only lists remote branches that I've tracked locally. How do I find the list of those that I haven't? (It doesn't matter to me whether the command lists all remote branches or only those that are untracked.)

20 Answers

Just run a git fetch command. It will pull all the remote branches to your local repository, and then do a git branch -a to list all the branches.

Try this...

git fetch origin
git branch -a

TL;TR;

This is the solution of your problem:

git remote update --prune    # To update all remotes
git branch -r                # To display remote branches

or:

git remote update --prune    # To update all remotes
git branch <TAB>             # To display all branches

Assuming you have the following branches on a remote repository: git branch -a gives you:

*remotes/origin/release/1.5.0
 remotes/origin/release/1.5.1
 remotes/origin/release/1.5.2
 remotes/origin/release/1.5.3
 remotes/origin/release/1.6.0

Based on above result command git branch -rl '*/origin/release/1.5*' gives you this:

 origin/release/1.5.1
 origin/release/1.5.2
 origin/release/1.5.3

-r stands for remote

-l list using <pattern>

The accepted answer works for me. But I found it more useful to have the commits sorted starting with the most recent.

git branch -r --sort=-committerdate

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

I would use:

git branch -av

This command not only shows you the list of all branches, including remote branches starting with /remote, but it also provides you the * feedback on what you updated and the last commit comments.

If there's a remote branch that you know should be listed, but it isn't getting listed, you might want to verify that your origin is set up properly with this:

git remote show origin

If that's all good, maybe you should run an update:

git remote update

Assuming that runs successfully, you should be able to do what the other answers say:

git branch -r
Related