Skip to content

Instantly share code, notes, and snippets.

@rokibhasansagar
Forked from Zibri/gitclean.sh
Last active September 6, 2023 18:02
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rokibhasansagar/e9d3634084ec52583b25eeea122fa43f to your computer and use it in GitHub Desktop.
Save rokibhasansagar/e9d3634084ec52583b25eeea122fa43f 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