假设要fork的仓库名称为a,你的本地仓库名称为b
- 克隆a仓库的ssh
git clone [email protected]:username/a.git
cd a
- 添加b仓库为上游(upstream)远程仓库
git remote add upstream [email protected]: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
标签:fork,git,grep,仓库,branch,upstream,分支
From: https://www.cnblogs.com/algoshimo/p/18293103