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

后端 未结 19 2228
轮回少年
轮回少年 2020-12-02 03:14

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

相关标签:
19条回答
  • 2020-12-02 03:46

    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'
    
    0 讨论(0)
  • 2020-12-02 03:47

    The simplest way I found:

    git branch -a
    
    0 讨论(0)
  • 2020-12-02 03:48

    Git Branching - Remote Branches

    git ls-remote
    

    Git documentation.

    0 讨论(0)
  • 2020-12-02 03:49

    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

    0 讨论(0)
  • 2020-12-02 03:53

    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.

    0 讨论(0)
  • 2020-12-02 03:54

    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
    
    0 讨论(0)
提交回复
热议问题