git 如何 fork 一个仓库的所有分支

假设要fork的仓库名称为a,你的本地仓库名称为b

  1. 克隆a仓库的ssh
git clone git@github.com:username/a.git

cd a
  1. 添加b仓库为上游(upstream)远程仓库
git remote add upstream git@github.com:username/b.git
  1. 获取所有分支
git fetch upstream
  1. 查看所有分支
git branch -r
  1. 创建本地分支以跟踪远程分支
for branch in $(git branch -r | grep 'upstream/' | grep -v 'upstream/HEAD' | sed 's/upstream\///'); do
  git checkout -b $branch upstream/$branch
done
  1. 推送所有分支到b
for branch in $(git branch -r | grep 'upstream/' | grep -v 'upstream/HEAD' | sed 's/upstream\///'); do
  git push origin $branch
done

posted @ 2024-07-10 08:31  拾墨、  阅读(97)  评论(1编辑  收藏  举报