Skip to content

Instantly share code, notes, and snippets.

@erykpiast
Created December 15, 2015 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erykpiast/0ec254b63803ef5697d3 to your computer and use it in GitHub Desktop.
Save erykpiast/0ec254b63803ef5697d3 to your computer and use it in GitHub Desktop.
Clean untracked files in git more safely
function git_clean_untracked_safely {
TO_REMOVE=`git clean -f -d -n`;
TO_REMOVE_LINES=`git clean -f -d -n | wc -l`;
if [ "$TO_REMOVE_LINES" -ne "0" ]; then
echo "Cleaning";
printf "\n$TO_REMOVE\n\n";
echo "Proceed?";
select result in Yes No; do
if [[ "$result" == "Yes" ]]; then
echo "Cleaning in progress..."
git clean -f -d;
echo "Cleaning finished!"
fi
break;
done;
else
echo "Everything is clean";
fi;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment