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

后端 未结 19 2229
轮回少年
轮回少年 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:54

    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.

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

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

    With Git Bash, you can use:

    git branch -a
    
    0 讨论(0)
  • 2020-12-02 03:58
    git branch -a | grep remotes/*
    
    0 讨论(0)
  • 2020-12-02 04:01

    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.

    0 讨论(0)
  • 2020-12-02 04:02

    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.

    0 讨论(0)
提交回复
热议问题