【英文】清理Git仓库
Introduction
Cleaning up local and remote Git repositories, keeping only the latest commit.
Switch to a new branch
- Switch to a new branch and keep only the latest code.
<new_branch>
: New branch name
1 | git checkout --orphan <new_branch> |
Commit the branch
1 | git add -A |
Delete old branch (optional)
<old_branch>
: Old branch name
1 | git branch -D <old_branch> |
Rename the new branch (optional)
- Change the new branch name to the previous branch name.
<branch_name>
: Renamed branch name
1 | git branch -m <branch_name> |
Force push to remote
master
: Branch name to push to remote
1 | git push -f origin <new_branch> |