In Git, list names of branches with unpushed commits

后端 未结 4 1143
深忆病人
深忆病人 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条回答
  •  谎友^
    谎友^ (楼主)
    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 /usr/bin includes 200+ linux commands (grep, sed, awk, xargs, ...)

提交回复
热议问题