Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save gederajeg/0e0153d699f607731b17f95f1912a3a8 to your computer and use it in GitHub Desktop.

Select an option

Save gederajeg/0e0153d699f607731b17f95f1912a3a8 to your computer and use it in GitHub Desktop.
Delete commit history to a clean slate and re-push this clean new history to different repo.

Asumming we have a fully tracked repo under main.

We follow these steps:

See method 3 here

Then when we want to push, we do:

git push prasasti latest:main --force (credit & source)

  • Whereby we force-push from an orphan branch (in this case I used latest branch) into the main branch in a remote repo I called prasasti

My complete history

git checkout --orphan latest

git status # check the files to remove

git rm -rf 02-04* # remove the desired files and directory

git status # double check

git commit -m "clean slate." # the clean slate commit

git log # check that there is only the previous single commit there

git push -f prasasti main # this command returns 'Everything up-to-date', which I DO NOT WANT, but then I found this

git push prasasti latest:main --force # this one works! (force-push into the remote directory prasasti content of the clean-slate latest local branch into remote main branch.

git checkout main # return to main

git branch -D latest # delete the temporary branch

I re-do the above steps and still working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment