Git: How do I list local branches that are tracking remote branches that no longer exist?

前端 未结 4 601
無奈伤痛
無奈伤痛 2020-12-16 14:32

How can I list any local branches that appear (as per .git/config) to be tracking remote branches that no longer exist? Remote branches are on GitHub in this ca

相关标签:
4条回答
  • 2020-12-16 14:36

    If your local branches are tracking the remote branch you can filter the list of branches so show the ones that do not have a tracking branch with:

    git branch -vv | grep -v origin
    

    This will provide some extra information about the last commit that is on the branch but you can filter that out

    git branch -vv | grep -v origin | awk '{print $1}'
    

    This will only print the name of the branch that isn't tracking a remote branch.

    0 讨论(0)
  • 2020-12-16 14:48
    LANG=en git branch --format='%(if:equals=gone)%(upstream:track,nobracket)%(then)%(refname:short)%(end)' | grep '.'
    
    0 讨论(0)
  • 2020-12-16 14:54
    git for-each-ref refs/heads --format='%(refname:short) %(upstream)' \
    | awk 'NF==1'
    

    will do it. NF is awk's "number of fields", and its default action is print.

    0 讨论(0)
  • 2020-12-16 15:01

    To list your local branches which track deleted remote branches you can use git remote prune --dry-run

    For example (assuming your remote repository is named origin):

    git fetch
    git remote prune origin --dry-run
    

    You can remove the --dry-run option to delete the branches from your local repository

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