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

后端 未结 10 510
南方客
南方客 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:26

    Why wouldn't this work:

    #!/bin/sh
    git diff origin/master..HEAD --quiet --exit-code
    RETVAL=$?
    if [ $RETVAL -gt 0 ]; then
        echo "You need to git push!"
    else
        echo "No git push necessary!"
    fi 
    

提交回复
热议问题