Last active
April 3, 2021 13:07
-
-
Save fagci/167b25438425c3b82124d9e8e61e8f6a to your computer and use it in GitHub Desktop.
Truncate git history to last state on remote repository (alternative variant)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# backup repo config | |
cp .git/config /tmp/truncate.git.config | |
# cleanup history | |
rm -rf .git | |
git init | |
# restore repo config | |
mv /tmp/truncate.git.config .git/config | |
# optional step | |
git branch -m main | |
# make first commit | |
git add . | |
git commit -m 'initial' | |
# truncate history on remote repo | |
git push --force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Made this as alternative to common approach.
This method preserves repository config.
One thing is to deal with branch name.