Skip to content

Instantly share code, notes, and snippets.

@egladman
Created February 12, 2017 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egladman/c377f7822326dfefffe0674002cf6388 to your computer and use it in GitHub Desktop.
Save egladman/c377f7822326dfefffe0674002cf6388 to your computer and use it in GitHub Desktop.
Prevent accidental changes from being committed to git
#Append the following snippet to your bash.rc
#Whenever "git add foo" is ran "git diff" will first run
#and require user confirmation before changes are added.
git() {
if [[ $1 == "add" ]]; then
command git diff
read -p "Are you sure? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
command git add "${@:(2)}"
fi
else
command git "$@"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment