核心思路,已有从源GitHub A仓库fork过来的A1仓库,clone A1仓库到本地,将另一个A仓库的分叉 A2仓库 的一个branch作为一个新建branch创建在本地,最后将其push到远程A1仓库中即可。

在GitHub上这个branch可以正常开pull requests到A2仓库或其他A仓库的分叉仓库,但Fetch upstream这个便利的功能就只能用于同步来自A仓库的branch,而来自于A2仓库的branch则不能享受这项便利的功能,得手动在本地fetch pull push。

clone A1仓库到本地

推荐使用远程仓库的ssh地址clone到本地。

git clone git@github.com:XXX/A1.git

如果已经clone过了,就与远程仓库同步一下保证后续步骤不会出错。

git fetch

git pull

添加remote A2远程仓库地址

查看当前remote远程仓库地址有哪些。

git remote -v

添加A2远程仓库地址,远程仓库别名可自定义,添加以后可以再用上面的命令确认一下。

git remote add <远程仓库别名> <仓库地址>|git remote add <remote> <url>

获取A2远程仓库的分支

git fetch <远程仓库别名> <分支>|git fetch <remote> <branch>

可以查看一下是否获取到远程仓库的分支。

git branch -a

从A2远程仓库的分支新建一个本地分支

git checkout -b <新分支名> --no-track <远程仓库别名>/<分支>

git checkout -b <branch> --no-track <remote>/<branch>

此时本地将新建并切换到这个分支,可以查看一下本地分支。

git branch -a

推送到A1远程仓库

origin远程仓库即我们自己的A1仓库,将本地分支推送到这里面去即可。

git push --set-upstream origin <分支>| git push --set-upstream origin <branch>

手动更新分支与A2仓库同步

git pull <远程仓库别名> <远程分支>:<本地分支>

git pull <remote> <branch>:<branch>

再推送到A1远程仓库。

git push

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐