git 如何 fork 一个仓库的所有分支
假设要fork的仓库名称为a,你的本地仓库名称为b
- 克隆a仓库的ssh
git clone git@github.com:username/a.git
cd a
- 添加b仓库为上游(upstream)远程仓库
git remote add upstream git@github.com:username/b.git
- 获取所有分支
git fetch upstream
- 查看所有分支
git branch -r
- 创建本地分支以跟踪远程分支
for branch in $(git branch -r | grep 'upstream/' | grep -v 'upstream/HEAD' | sed 's/upstream\///'); do
git checkout -b $branch upstream/$branch
done
- 推送所有分支到b
for branch in $(git branch -r | grep 'upstream/' | grep -v 'upstream/HEAD' | sed 's/upstream\///'); do
git push origin $branch
done