Cleaning up local and remote Git repositories, keeping only the latest commit.
- Switch to a new branch and keep only the latest code.
<new_branch>: New branch name
git checkout --orphan <new_branch>
git add -A
<old_branch>: Old branch name
git branch -D <old_branch>
- Change the new branch name to the previous branch name.
<branch_name>: Renamed branch name
git branch -m <branch_name>
master: Branch name to push to remote
git push -f origin <new_branch>