工作中, 我们会遇到这样的场景, 从 github 上拉了一些项目代码下来, 修改到一半需要回家了, 但不想 push 上 github, 也不想用硬盘拷贝, 这时可以先 push 到私有仓库中, 回家继续修改之后, 再推送到 github 仓库中.
把 github 仓库的代码推送到另外一个仓库(OSC)
假设现在我从 github 上 clone 了 dubbo 的仓库下来, 然后我改了东西, 现在我要推送到 osc 开源中国的私有 git 仓库中, 以下是完整操作:
# 把origin改名为github, 方便识别 |
有了多个 remote , 不仅可以完成 github -> osc , 还可以将 osc -> github .
常见问题
推送分支和远程 tag 名相同 - refspec matches more than one.
错误:
$ git push --set-upstream osc dubbo-2.4.11 |
解决:
$ git push osc HEAD:dubbo-2.4.11 |
不过, 最好不要用相同的 tag 和 branch 名字.
参考: http://stackoverflow.com/questions/9378760/git-push-local-branch-with-same-name-as-remote-tag
tag 和 branch 重名问题
相同的 tag 和 branch 名字容易出现各种问题, 不推荐使用. 比如推送分支 dubbo-2.4.11
时的提示 :
refname 'dubbo-2.4.11' is ambiguous
解决方法一: 改 branch
改变分支名, 删掉旧的分支.
# 新的分支名 |
解决方法二: 改 tag
使用 git tag [tag] [commit]
先重命名保存原来的 tag , 然后删掉.
# 将 dubbo-2.4.11 的 commit 使用 tag 为 dubbo-2.4.11-tag |
参考: http://stackoverflow.com/questions/12224773/git-refname-master-is-ambiguous
参考
http://stackoverflow.com/questions/5181845/git-push-existing-repo-to-a-new-and-different-remote-repo-server
https://www.atlassian.com/git/tutorials/using-branches/git-branch