网站首页 > 技术教程 正文
一直以来想把自己的博客代码托管到github 和coding上 想一次更改 一次push 两个地址一起更新 今天有空查资料 实践了下
本博客的
github地址
coding的git地址
如果是 Git,一般来说最佳方法是给 origin 设两个地址:
Use case 1: 多地址的 remote repo:
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。
只用于 push 的备份 repo
另外一种 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
猜你喜欢
- 2024-10-27 git安装使用 git的安装流程
- 2024-10-27 代码即将上线,突然有个中间提交不能发布!怎么办?
- 2024-10-27 git 将本地还原至某次提交 git还原到指定版本
- 2024-10-27 git reset 和 git rever 实践 git的reset
- 2024-10-27 这有一份 Git 日常使用清单,你需要吗?
- 2024-10-27 Git教学篇2-git日常操作之git clone与git tag
- 2024-10-27 git clone切换分支步骤,代理设置,作者信息设置
- 2024-10-27 Git 高级用法,喜欢就拿去用 git常用
- 2024-10-27 Git 必知必会《续》 git hint
- 2024-10-27 git的使用 git基本用法
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- sd分区 (65)
- raid5数据恢复 (81)
- 地址转换 (73)
- 手机存储卡根目录 (55)
- tcp端口 (74)
- project server (59)
- 双击ctrl (55)
- 鼠标 单击变双击 (67)
- debugview (59)
- 字符动画 (65)
- flushdns (57)
- ps复制快捷键 (57)
- 清除系统垃圾代码 (58)
- web服务器的架设 (67)
- 16进制转换 (69)
- xclient (55)
- ps源文件 (67)
- filezilla server (59)
- 句柄无效 (56)
- word页眉页脚设置 (59)
- ansys实例 (56)
- 6 1 3固件 (59)
- sqlserver2000挂起 (59)
- vm虚拟主机 (55)
- config (61)
本文暂时没有评论,来添加一个吧(●'◡'●)