Skip to content

Instantly share code, notes, and snippets.

@gmolveau
Last active July 27, 2020 14:15
Show Gist options
  • Select an option

  • Save gmolveau/ec8309d8787e324cc466f9fea5a4e958 to your computer and use it in GitHub Desktop.

Select an option

Save gmolveau/ec8309d8787e324cc466f9fea5a4e958 to your computer and use it in GitHub Desktop.
Watching a remote git repository - checking if new commits available

Watch a remote git repo

In a folder :

  • copy this script in a file watch.sh :
#!/usr/bin/env bash
set -euo pipefail

function watch {(
    cd repo
    git remote update 2>/dev/null 1>/dev/null
    LOCAL=$(git rev-parse @)
    BASE=$(git merge-base @ "@{u}")
    if [ "$LOCAL" = "$BASE" ]; then
        action
    fi
)}

function action {(
    echo "Need to pull"
    # do something
)}

watch
  • clone the repo you want to watch :
git clone https://github.com/:author/:repo repo
  • run the script via cron or manually
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment