Git-项目指向另一个远程仓库

转载请注明出处:www.huamo.online
字节杭州 求贤若渴:

  1. https://job.toutiao.com/s/JXTdQaH
  2. https://job.toutiao.com/s/JXTMWW3
  3. https://job.toutiao.com/s/JXT1tpC
  4. https://job.toutiao.com/s/JXTdu6h

项目代码推送到另一个远程仓库

例如现在有一个项目test,并且在本地dev分支做开发,这个dev分支跟踪了远程的分支为origin/dev。现在的需求是:将test项目代码推送到另一个仓库anotherprd分支上

添加remote

1
$ git remote add another https://git.com/another

拉取anotherprd分支

1
$ git fetch another prd

本地建立prd分支跟踪another/prd

1
$ git checkout -b prd another/prd

到这里,你已经自动切换到了another/prd分支上了

拉取another/prd更新

1
$ git pull another prd:prd

dev分支代码全部合并到prd分支中

1
2
3
4
5
6
7
8
$ git branch -vv
* prd 6261ec6da [another/prd] production board!
dev e214411f9 [origin/dev] dev to make money!

// 可以看到目前确实在prd分支上

$ git merge dev
// 合并代码,手动解决所有的冲突

推送代码到another/prd分支中

1
2
3
$ git add .
$ git commit -m "commit code"
$ git push another prd:prd

转载请注明出处:www.huamo.online