When submitting a project to GitHub, you might accidentally include sensitive information like passwords or email addresses. Here's how to remove those records, create a brand-new repository, and keep the code unchanged:
-
Create a new blank branch
git checkout --orphan latest_branch
-
Add all files
git add -A
-
Commit the changes
git commit -am "."
-
Force delete the old branch (e.g., if it’s
main
)
git branch -D main
-
Rename the current branch to
main
git branch -m main
-
Force push to the remote repository
git push -f origin main