In Git, list names of branches with unpushed commits

后端 未结 4 1101
深忆病人
深忆病人 2021-01-30 13:02

Given a project with several local branches, each tracking some remote branch, is there a command that lists all branches that have unpushed commits? (That is, even if none of t

相关标签:
4条回答
  • although the answers above are very helpful and show alot of data but for others coming here looking for a solution to find local branches which are ahead i.e. have not been pushed yet. can get the exact list by executing:

    git branch -v | grep ahead
    
    0 讨论(0)
  • 2021-01-30 13:24

    The --no-walk option to log seems to do a better job of what I need than --simplify-by-decoration. My full command is:

    git log --branches --not --remotes --no-walk --decorate --oneline

    ...which I've aliased to unpushed.

    0 讨论(0)
  • 2021-01-30 13:28

    You can also see what branches are not yet merged to master

    git checkout master
    

    and then

    git branch --no-merged
    
    0 讨论(0)
  • 2021-01-30 13:30
    git for-each-ref --format="%(refname:short) %(push:track)" refs/heads
    

    That remain the most precise answer that you can easily parse/grep to get the desired output (like removing up-to-date branches)

    You can do so in a bash script that you will call git-xxx (no extension), somewhere in your $PATH or %PATH%.
    That script can then be called with git xxx, and will use git bash.
    That is portable and will work across platforms (meaning even on Windows, where <Git For Windows>/usr/bin includes 200+ linux commands (grep, sed, awk, xargs, ...)

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