git 实现一份代码push到两个git地址上
来源:     阅读:9
易浩激活码
发布于 2025-10-22 18:02
查看主页


一直以来想把自己的博客代码托管到github 和coding上 想一次更改 一次push 两个地址一起更新 今天有空查资料 实践了下

本博客的

github地址

coding的git地址

如果是 Git,一般来说最佳方法是给 origin 设两个地址:

git remote set-url origin --add https://coding.net/u/niefengjun/p/blog_es6/git

git remote set-url origin --add https://github.com/niefengjun/boke

在 .git/config 里得到

...

[remote "origin"]

url = https://coding.net/u/niefengjun/p/blog_es6/git

url = https://github.com/niefengjun/boke

...

[branch "master"]

remote = origin

...

然后

git push origin master

就会同时提交到两个 repo,而

git pull origin master

会从两个 repo 里取得更新。

当然 URL 和 repo 不必定非要是 GitHub 上的,具有两个 url 的 remote 也不必定要是 origin,列如可以设置成 all。

另外一种 use case,你想从 repo1 pull,但是 push 的时候要推送到 repo1 和另一个 repo2,

git remote set-url origin --add https://coding.net/u/niefengjun/p/blog_es6/git

git remote set-url origin --push --add https://github.com/niefengjun/boke

在 .git/config 里得到

...

[remote "origin"]

url = https://coding.net/u/niefengjun/p/blog_es6/git

pushurl = https://github.com/niefengjun/boke

...

[branch "master"]

remote = origin

...

然后

git push origin master

就会同时提交到两个 repo,而

git pull origin master

会从两个 GitHub repo1 里取得更新。

有时候第一个git 已经开发了 才想起来增加第二个 这个的话 会被告知 第二个本地没有分支

error: failed to push some refs to 'git@github.com:niefengjun/boke.git'

hint: Updates were rejected because the remote contains work that you do

hint: not have locally. This is usually caused by another repository pushing

hint: to the same ref. You may want to first integrate the remote changes

hint: (e.g., 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.

这个时候用命令

git push -f origin master

即可完成提交

至此后来提交的话 会在两个git 上看到我的更新代码

http://www.niefengjun.cn/blog/0277690638201db4b26b608a09900a5e.html

免责声明:本文为用户发表,不代表网站立场,仅供参考,不构成引导等用途。 系统环境
相关推荐
windows下mysql自动备份及备份同步至NAS解决方案
聊聊storm的GraphiteStormReporter
从Vue2.0到React17——React开发入门
Vue.js 组件复用和扩展之道
想挖杨紫的黑料比登天还难,她的好人品在圈内有目共睹,活该被人喜爱
首页
搜索
订单
购物车
我的