Skip to content

Instantly share code, notes, and snippets.

@raulmarcosl
Last active August 29, 2015 14:02
Show Gist options
  • Save raulmarcosl/6833093731b851f40845 to your computer and use it in GitHub Desktop.
Save raulmarcosl/6833093731b851f40845 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ "$#" -ge 1 ]; then
echo "Are you sure (y/n)?"
read answer
# Abort unless enter was pressed, or "y" written
if [ "$answer" = "y" ] || [ "$answer" = "" ]; then
git checkout "$@"
else
echo "aborted"
fi
else
echo "Incorrect number of arguments"
fi
@raulmarcosl
Copy link
Author

Instructions to ask before execute git checkout (aliased to git co):

  • Copy ask_before_checkout.sh in a folder included in $PATH (or include the folder).
  • Type this:
git config --global alias.co '!sh ask_before_checkout.sh'

Note: The bang at the start of the alias means "run the following as commands to the shell".

@manuartero
Copy link

So useful!

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