Skip to content

Instantly share code, notes, and snippets.

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 przemyslawjanpietrzak/c62df237a26317e6671c423c3333c31d to your computer and use it in GitHub Desktop.
Save przemyslawjanpietrzak/c62df237a26317e6671c423c3333c31d 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