Check if pull needed in Git

后端 未结 24 1566
忘了有多久
忘了有多久 2020-11-22 13:34

How do I check whether the remote repository has changed and I need to pull?

Now I use this simple script:

git pull --dry-run | grep -q -v \'Already          


        
24条回答
  •  萌比男神i
    2020-11-22 13:59

    Using simple regexp:

    str=$(git status) 
    if [[ $str =~ .*Your\ branch\ is\ behind.*by.*commits,\ and\ can\ be\ fast-forwarded ]]; then
        echo `date "+%Y-%m-%d %H:%M:%S"` "Needs pull"
    else
        echo "Code is up to date"
    fi
    

提交回复
热议问题