Git 把码云上被fork项目源码merge到fork出来的分支项目

Git 把码云上被fork项目源码merge到fork出来的分支项目

 

By:授客 QQ1033553122

 

需求描述

被fork的项目有更新代码,希望把更新的代码merge到fork分支项目

 

解决方法

1、clone fork分支项目到本地,并入切换当前分支为目标分支。

 

2、增加被fork项目源码仓库地址到你项目远程分支列表中),并将该仓库地址命名为upstream(当然也可以是其它),如下:

git remote add upstream https://github.com/srcRepo.git

 

其中 srcReop为被fork项目

 

3、取回远程主机被fork项目的全部更新

git fetch upstream

 

当然,也可以指定只取回目标分支

git fetch upstream remoteTargeBranch

 

4、合并取回的目标分支(例中为master)代码到本地当前分支

git merge upstream/master

 

至此,完成了本地代码的合并,接下来只需要push到fork项目的目标分支即可。

 

步骤3,步骤4也可以直接使用pull命令替代,合并为一个步骤,如下

git pull upstream master

 

实例

(例中使用ssh访问仓库)

 

进入对应项目的 git bash后执行的以下命令

 

cassmall@DESKTOP-O45PJTA MINGW64 /e/PrivateReops/CassTestManage (V2.0)

$ git remote add upstream [email protected]:xxxx/CassTestManage.git

 

cassmall@DESKTOP-O45PJTA MINGW64 /e/PrivateReops/CassTestManage (V2.0)

$ git remote -v

origin  [email protected]:laiy/CassTestManage.git (fetch)

origin  [email protected]:laiy/CassTestManage.git (push)

upstream        [email protected]:xxxx/CassTestManage.git (fetch)

upstream        [email protected]:xxxx/CassTestManage.git (push)

 

cassmall@DESKTOP-O45PJTA MINGW64 /e/PrivateReops/CassTestManage (V2.0)

$ git pull upstream master

remote: Enumerating objects: 64, done.

remote: Counting objects: 100% (64/64), done.

remote: Compressing objects: 100% (63/63), done.

remote: Total 64 (delta 0), reused 58 (delta 0)

Unpacking objects: 100% (64/64), done.

From gitee.com3:xxxx/CassTestManage

 * branch            master     -> FETCH_HEAD

 * [new branch]      master     -> upstream/master

Merge made by the 'recursive' strategy.

 mytest.txt | 1 +

 1 file changed, 1 insertion(+)

 create mode 100644 mytest.txt

 

cassmall@DESKTOP-O45PJTA MINGW64 /e/PrivateReops/CassTestManage (V2.0)

$

 

说明

第二次开始,可以通过git客户端界面进行代码的合并操作,非常简单,如下指定远程主机和要pull的分支即可。

 

 

猜你喜欢

转载自www.cnblogs.com/shouke/p/12186717.html