git合并仓库代码

先说一下场景 公司有两个git仓库 测试仓库test 正式仓库prod 需要先把测试仓库的代码合并到正式仓库 发版直接拉取正式仓库代码即可

1.先查看本地仓库

$ git remote -vv
origin  https://gitee.com/test.git (fetch)
origin  https://gitee.com/test.git (push)

2.添加正式仓库

$ git remote add prod https://gitee.com/prod.git

3.查看本地仓库

$ git remote -vv
prod    https://gitee.com/prod.git (fetch)
prod    https://gitee.com/prod.git (push)
origin  https://gitee.com/test.git (fetch)
origin  https://gitee.com/test.git (push)

4.将正式仓库拉取下来

$ git fetch prod
From https://gitee.com/prod.git
 * [new branch]          hotfix          -> prod/hotfix
 * [new branch]          master          -> prod/master

5.将prod仓库抓取的hotfix分支作为新分支checkout到本地,新分支名设定为new_branch

$ git checkout -b new_branch prod/hotfix
Switched to a new branch 'new_branch'
Branch 'new_branch' set up to track remote branch 'hotfix' from 'prod'.

6.checkout到测试的hotfix分支

$ git checkout hotfix
Switched to branch 'hotfix'
Your branch is up to date with 'origin/hotfix'.

7.将new_branch合并入hotfix分支

$ git merge new_branch

8.提交

$ git add .
$ git commit -m "合并"
$ git push prod hotfix

你可能感兴趣的:(git合并仓库代码)