克隆后将本地git设为单分支

问题描述 投票:0回答:1

几年前我开始了一个 git 仓库,现在仓库已经变得很大了。应用后

.git
文件夹很大,多了50GB如何缩小.git文件夹

远程分支的数量也很大,有没有办法让我的本地 git 仓库成为“单一分支”而不需要重新克隆它?

git github gitlab
1个回答
0
投票

我建议您再次克隆它,但通过以下命令提供特定分支作为源:

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
© www.soinside.com 2019 - 2024. All rights reserved.