Check if pull needed in Git

后端 未结 24 1567
忘了有多久
忘了有多久 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 14:16

    There are many very feature rich and ingenious answers already. To provide some contrast, I could make do with a very simple line.

    # Check return value to see if there are incoming updates.
    if ! git diff --quiet remotes/origin/HEAD; then
     # pull or whatever you want to do
    fi
    

提交回复
热议问题