Skip to content

Instantly share code, notes, and snippets.

@toineheuvelmans
Created June 25, 2020 08:10
Show Gist options
  • Save toineheuvelmans/d5e57dc8afb50bfb3596d802bf30b5b0 to your computer and use it in GitHub Desktop.
Save toineheuvelmans/d5e57dc8afb50bfb3596d802bf30b5b0 to your computer and use it in GitHub Desktop.
Check local repo changes before proceeding with other commands
#!/bin/bash
# Exits with error if there are uncommitted changes.
# This can be used as follows:
# $ ./git-safeguard.sh && <other commands>
# to only execute the other commands if there are no changes.
if [[ $(git status -s) ]]; then
echo "There are uncommitted changes:"
git status -s
exit 1
fi
@toineheuvelmans
Copy link
Author

If you use some tool that pulls files from a service, you can use this safeguard to only proceed pulling if there are no local changes. This avoids files getting overwritten unexpectedly.

In my case I use this in the context of clasp pull (from Google), which I safeguard in my Makefile like so:

pull:
    ./git-safeguard.sh && clasp pull

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment