- Checkout
tmp
branch without history, from whatever targeted commit or branch you want - Delete targeted branch
- Rename
tmp
branch to targeted branch - Force push to repo
git checkout --orphan tmp #KEY STEP IS TO CHECKOUT AS ORPHAN
git add -A
git commit -am "init"
git branch -D master
git branch -M master
git push -f origin master
#!/bin/sh
TARGET='master'
git checkout "$TARGET"
git checkout --orphan tmp
git add -A
git commit -am "init"
git branch -D "$TARGET"
git branch -M "$TARGET"
git push -f origin "$TARGET"