How To Delete All Past Commits in a Git Branch (Short and Sweet!)

preview_player
Показать описание
git checkout --orphan new_branch (new branch)
git add . (use this in root directory only)
git commit -m "ur message here"
git branch -D main (delete main branch)
git branch -m main (rename current branch to 'main')
git push -f origin main (push and finish)
Рекомендации по теме
Комментарии
Автор

This was one of the reason the company fired me ( I think it was bs from their side but I accept it ), I did not created --orphan branch, just a new one and there were the commits from the main branch. Now I learned different tricks about, and this one is the best. Thank you mate

untildawn
Автор

You were better than chatGPT, thank you 💓

leorip
Автор

Thanks man, this is the best answer i found after hours of searching and reading sh+ t posts and youtube videos

xVinoz
Автор

bro, you nailed it! this was short and easy! thanks!

JmMazTaRY
Автор

Thanks, super simple and to the point!

MuhammadFaisal-eyfr
Автор

Thanks for this tutorial, helped me alot.

NHCS_MABUD
Автор

Thank you this is totally what i needed.

KeithGyarmati
Автор

Hey. i want to delete certain commits from my github history only.. not all of them .

how would i delete specific pushed commits on my github repo. where the commit is from me deleting files/folders and then just commiting those changes and pushing them

Yeet_the_code
Автор

Did not work for me for some reason. Locally I do have only 1 commit. But on my github repository I have all previous commits + last one

If i check my branches with 'git branch -a' command it shows:

- main
- remotes/origin/HEAD -> origin/main
- remotes/origin/main

Do I need to delete one remote branch ?

I guess because I had remote main branch last commit did get pushed to the old branch...

can-not-break
Автор

when i write the first sentence and press enter it says fatal: not a git repository (or any of the parent directories): .git, help man, i really need this to work

assassinmykolas
Автор

How to delete the files added in master branch

syedsiddiq