---
url: https://eoht.net/fe/git/clean-up.md
description: 学习如何使用 Git 缩减仓库大小，清理历史记录和不必要的文件，提高仓库的性能和效率。
---

# Git 缩减仓库 优化 Git 仓库大小 提高性能 {#reduce-git-repository-size}

```sh
# 清除垃圾文件 - 大量无用的 mp3 文件
git filter-repo --path-glob '*.mp3' --invert-paths --force

# 列出标签和分支，删除不需要的
git tag -d <tag_name>
git push origin --delete <tag_name>

git branch -d <branch_name>
git push origin --delete <branch_name>

# 清理垃圾回收并重新打包对象
git reflog expire --expire=now --all
git gc --prune=now --aggressive
git repack -Ad
git prune

# 推送修改后的历史记录回远程仓库
git remote add origin <https://github.com/username/repository.git>
git push origin --force --all
git push origin --force --tags
```

## Git 学习路径 {#git-learning-path}

历史清理会改变提交记录，操作前可先对照 [Git 重置提交记录](/fe/git/reset-commit)；如果只需要日常分支和标签操作，返回 [Git 常用命令](/fe/git/command)。
