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

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.)

This question is related to git branch git-branch remote-branch

The answer is


Using this command,

git log -r --oneline --no-merges --simplify-by-decoration --pretty=format:"%n %Cred CommitID %Creset: %h %n %Cred Remote Branch %Creset :%d %n %Cred Commit Message %Creset: %s %n"

CommitID       : 27385d919
Remote Branch  : (origin/ALPHA)
Commit Message :  New branch created

It lists all remote branches including commit messages and commit IDs that are referred to by remote branches.


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.


Try this...

git fetch origin
git branch -a

You also may do git fetch followed by a git branch -r. Without fetch you will not see the most current branches.


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

With Git Bash, you can use:

git branch -a

Using git branch -r lists all remote branches and git branch -a lists all branches on local and remote. These lists get outdated though. To keep these lists up-to-date, run

git remote update --prune

which will update your local branch list with all new ones from the remote and remove any that are no longer there. Running this update command without the --prune will retrieve new branches but not delete ones no longer on the remote.

You can speed up this update by specifying a remote, otherwise it will pull updates from all remotes you have added, like so

git remote update --prune origin

But

git branch -ar

should do it.


git branch -a | grep remotes/*

I ended up doing a mess shell pipeline to get what I wanted. I just merged branches from the origin remote:

git branch -r --all --merged \
    | tail -n +2 \
    | grep -P '^  remotes/origin/(?!HEAD)' \
    | perl -p -e 's/^  remotes\/origin\///g;s/master\n//g'

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

Make sure that the remote origin you are listing is really the repository that you want and not an older clone.


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.


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


Git Branching - Remote Branches

git ls-remote

Git documentation.


The simplest way I found:

git branch -a

remote show shows all the branches on the remote, including those that are not tracked locally and even those that have not yet been fetched.

git remote show <remote-name>

It also tries to show the status of the branches relative to your local repository:

> git remote show origin
* remote origin
  Fetch URL: C:/git/.\remote_repo.git
  Push  URL: C:/git/.\remote_repo.git
  HEAD branch: master
  Remote branches:
    branch_that_is_not_even_fetched new (next fetch will store in remotes/origin)
    branch_that_is_not_tracked      tracked
    branch_that_is_tracked          tracked
    master                          tracked
  Local branches configured for 'git pull':
    branch_that_is_tracked merges with remote branch_that_is_tracked
    master                 merges with remote master
  Local refs configured for 'git push':
    branch_that_is_tracked pushes to branch_that_is_tracked (fast-forwardable)
    master                 pushes to master                 (up to date)

The best command to run is git remote show [remote]. This will show all branches, remote and local, tracked and untracked.

Here's an example from an open source project:

> git remote show origin
* remote origin
  Fetch URL: https://github.com/OneBusAway/onebusaway-android
  Push  URL: https://github.com/OneBusAway/onebusaway-android
  HEAD branch: master
  Remote branches:
    amazon-rc2                   new (next fetch will store in remotes/origin)
    amazon-rc3                   new (next fetch will store in remotes/origin)
    arrivalStyleBDefault         new (next fetch will store in remotes/origin)
    develop                      tracked
    master                       tracked
    refs/remotes/origin/branding stale (use 'git remote prune' to remove)
  Local branches configured for 'git pull':
    develop merges with remote develop
    master  merges with remote master
  Local refs configured for 'git push':
    develop pushes to develop (local out of date)
    master  pushes to master  (up to date)

If we just want to get the remote branches, we can use grep. The command we'd want to use would be:

grep "\w*\s*(new|tracked)" -E

With this command:

> git remote show origin | grep "\w*\s*(new|tracked)" -E
    amazon-rc2                   new (next fetch will store in remotes/origin)
    amazon-rc3                   new (next fetch will store in remotes/origin)
    arrivalStyleBDefault         new (next fetch will store in remotes/origin)
    develop                      tracked
    master                       tracked

You can also create an alias for this:

git config --global alias.branches "!git remote show origin | grep \w*\s*(new|tracked) -E"

Then you can just run git branches.


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to branch

Get git branch name in Jenkins Pipeline/Jenkinsfile Why do I have to "git push --set-upstream origin <branch>"? Your configuration specifies to merge with the <branch name> from the remote, but no such ref was fetched.? When does Git refresh the list of remote branches? Fix GitLab error: "you are not allowed to push code to protected branches on this project"? Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository." Git: Merge a Remote branch locally git pull from master into the development branch Depend on a branch or tag using a git URL in a package.json? How can I copy the content of a branch to a new local branch?

Examples related to git-branch

How do I rename both a Git local and remote branch name? How do I create a master branch in a bare Git repository? git switch branch without discarding local changes Git: Merge a Remote branch locally Why call git branch --unset-upstream to fixup? Create a remote branch on GitHub How can I display the current branch and folder path in terminal? Git merge master into feature branch Delete branches in Bitbucket Creating a new empty branch for a new project

Examples related to remote-branch

When does Git refresh the list of remote branches? What are the differences between git remote prune, git prune, git fetch --prune, etc Git: Cannot see new remote branch Update a local branch with the changes from a tracked remote branch Git: which is the default configured remote for branch? How do I list all remote branches in Git 1.7+? How do I check out a remote Git branch? How do you remove an invalid remote branch reference from Git? Git checkout: updating paths is incompatible with switching branches How to clone all remote branches in Git?