本文记录一个比较不常用的git操作,场景为将一个库的某个分支,覆盖另一个库的某个分支。
. git_test, branch dev : github.com:xiangbin1997/git_test.git
. git_test1, branch master: github.com:xiangbin1997/git_test1.git

用git_test1,branch dev 替换 git_test, branch master

clone git_test1的dev分支

[postgres@hgcndn git_test1_dev]$ git clone -b dev git@github.com:xiangbin1997/git_test1.git
Cloning into 'git_test1'...
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 16 (delta 1), reused 11 (delta 0), pack-reused 0
Receiving objects: 100% (16/16), done.
Resolving deltas: 100% (1/1), done.
[postgres@hgcndn git_test1_dev]$ cd git_test1/

添加remote2,指向git_test

[postgres@hgcndn git_test1]$ git remote add origin2 git@github.com:xiangbin1997/git_test.git

修改branch 为master
*如果覆盖同名branch,则这一步不需要

git branch -m dev master

强制push到git_test的dev分支下

[postgres@hgcndn git_test1]$ git push -u origin2 master --force

说明,如果不强制push会报错

参考
git-move-repository


黑暗森林
12 声望2 粉丝

弱小和无知不是生存的障碍,傲慢才是!


« 上一篇
git常用操作
下一篇 »
整体迁移git