Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 498
James A. Rosen Avatar asked Aug 12 '10 20:08

James A. Rosen


People also ask

What is the git command to see all the remote branches?

To view your remote branches, simply pass the -r flag to the git branch command. You can inspect remote branches with the usual git checkout and git log commands.


2 Answers

For the vast majority[1] of visitors here, the correct and simplest answer to the question "How do I list all remote branches in Git 1.7+?" is:

git branch -r 

For a small minority[1]git branch -r does not work. If git branch -r does not work try:

git ls-remote --heads <remote-name> 

If git branch -r does not work, then maybe as Cascabel says "you've modified the default refspec, so that git fetch and git remote update don't fetch all the remote's branches".


[1] As of the writing of this footnote 2018-Feb, I looked at the comments and see that the git branch -r works for the vast majority (about 90% or 125 out of 140).

If git branch -r does not work, check git config --get remote.origin.fetch contains a wildcard (*) as per this answer

like image 186
Dustin Avatar answered Oct 21 '22 10:10

Dustin


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) 
like image 28
Klas Mellbourn Avatar answered Oct 21 '22 11:10

Klas Mellbourn