Skip to content

Instantly share code, notes, and snippets.

@robertoentringer
Last active May 12, 2019 00:16
Show Gist options
  • Save robertoentringer/c9e327479f012bafeaeaaf48d3966aaf to your computer and use it in GitHub Desktop.
Save robertoentringer/c9e327479f012bafeaeaaf48d3966aaf to your computer and use it in GitHub Desktop.
Bash script to clear out the history of a git/github repository.

Call directly from your terminal

$ bash <(curl -s https://gist.githubusercontent.com/robertoentringer/c9e327479f012bafeaeaaf48d3966aaf/raw)
#!/bin/bash
function gitclear() {
repo=`git config --get remote.origin.url`
[[ -z "$repo" ]] && { echo "Git remote origin url not found in: `pwd`"; return; }
info="All commits (local and remote) will be lost!"$'\n'
question="Are you sure you wish to continue? [N/y] "
read -p "$info$question" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -fr .git
git init
git add -A
git commit -m "Initial commit"
git remote add origin $repo
git push -u --force origin master
fi
}
gitclear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment