几年前我开始了一个 git 仓库,现在仓库已经变得很大了。应用后
.git
文件夹很大,多了50GB如何缩小.git文件夹。
远程分支的数量也很大,有没有办法让我的本地 git 仓库成为“单一分支”而不需要重新克隆它?
我建议您再次克隆它,但通过以下命令提供特定分支作为源:
git clone -b <branch-name> --single-branch <repository-url>
相反,如果您需要使用一堆特定分支,则应该尝试执行以下步骤:
# Initialize a new empty local repository
mkdir <repository-name>
cd <repository-name>
git init
# Add the remote repo url
git remote add -f origin <repository-url>
# Enable sparse-checkout (for this repo only)
git config core.sparseCheckout true
# Declare which branches you want to pull each time you issue a pull command
echo "my_branch1/*" >> .git/info/sparse-checkout
echo "my_branch2/*" >> .git/info/sparse-checkout
# Pull your remote branches
git pull origin master