연습하다보면 불필요한 commit 이력이 수십개가 되고, 다시 repo 삭제>생성하는 것이 번거로울 때 사용
# copy and paste
git checkout --orphan latest_branch
git add --all
git commit -am "commit message"
git branch -D main
git branch -m main
git push -f origin main
-----Step by description-----------
#Checkout
git checkout --orphan latest_branch
#Add all the files
git add --all
#Commit the changes
git commit -am "commit message"
#Delete the branch
git branch -D main
#Rename the current branch to main
git branch -m main
#Finally, force update your repository
git push -f origin main
git pull origin {BranchName} --allow-unrelated-histories
git pull origin main --allow-unrelated-histories
# git delete cached
git rm -r --cached .
git add .
git commit -am 'git cache cleared'
git push
_
반응형