我从分支机构克隆了一个来自Github的项目,比如br1
git clone --branch br1 https://www.github.com/project/project /opt/project/
我想切换到分支br2,好像我从一开始就这样做了:
git clone --branch br2 https://www.github.com/project/project /opt/project/
我不想在本地使用所有分支,只有我使用的分支,因为我在资源有限的VPS上。
我可以这样做(第一行的伪代码)吗?
git fetch origin/br2
git branch -D br1
编辑:这是我的.config
# cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = https://www.github.com/project/project
[branch "br1"]
remote = origin
merge = refs/heads/br1
答案 0 :(得分:2)
最简单的方法是:
再次进行克隆
git clone --branch br2 https://www.github.com/project/project /opt/project/
这会将网络活动限制到最小,就像自定义提取一样(但克隆比这里的提取更简单)
如果您想测试获取选项:
git remote rm origin
git remote add -t branch2 origin remote-url
git fetch origin