Created
June 25, 2020 08:10
-
-
Save toineheuvelmans/d5e57dc8afb50bfb3596d802bf30b5b0 to your computer and use it in GitHub Desktop.
Check local repo changes before proceeding with other commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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