git: programmatically know by how much the branch is ahead/behind a remote branch

后端 未结 10 514
南方客
南方客 2021-01-30 10:29

I would like to extract the information that is printed after a git status, which looks like:

# On branch master
# Your branch is ahead of \'origin/         


        
10条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-30 11:27

    You can try git branch -v -v. With -v flag given twice, it outputs names of upstream branches. Sample output:

    * devel  7a5ff2c [origin/devel: ahead 1] smaller file status overlay icons
      master 37ca389 [origin/master] initial project check-in.
    

    I think this format is more stable than git status output.

提交回复
热议问题