Skip to content

Instantly share code, notes, and snippets.

@fabianmossberg
Forked from rokibhasansagar/gitclean.sh
Created June 17, 2021 08:54
Show Gist options
  • Save fabianmossberg/da1bf49d258b3af04defc5e25920f1b2 to your computer and use it in GitHub Desktop.
Save fabianmossberg/da1bf49d258b3af04defc5e25920f1b2 to your computer and use it in GitHub Desktop.
Bash script to remove all revisions from github or gist repository.
#!/bin/bash
#
# By Zibri (2019)
# Modified by @rokibhasansagar
#
# Usage: gitclean git-repo-url
#
gitclean ()
{
git clone "$1" workDir && {
cd workDir/
for BR in $(git branch | tr " " "\n" | grep -v '*')
do
echo "working on branch $BR"
git checkout $BR
git checkout --orphan cross
git add -A
git commit -m "Initial Commit" && {
git branch -D $BR
git branch -m $BR
git push -f origin $BR
git gc --aggressive --prune=all
}
done
}
cd $currDir
rm -rf workDir
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment