Check if pull needed in Git

后端 未结 24 1655
忘了有多久
忘了有多久 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条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 13:57

    For the windows users who end up on this question looking for this, I've modified some of the answer into a powershell script. Tweak as necessary, save to a .ps1 file and run on demand or scheduled if you like.

    cd C:\
    git remote update                           #update remote
    $msg = git remote show origin               #capture status
    $update = $msg -like '*local out of date*'
    if($update.length -gt 0){                   #if local needs update
        Write-Host ('needs update')
        git pull
        git reset --hard origin/master
        Write-Host ('local updated')
    } else {
        Write-Host ('no update needed')
    }
    

提交回复
热议问题