网站首页 > 精选文章 正文
一直以来想把自己的博客代码托管到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-12-16 Git 两个常见错误
- 2024-12-16 SVN与Git的区别,读完之后,大部分程序员都收藏了...
- 2024-12-16 这样配置使用GIT命令clone/push/pull等不再重复输入密码
- 2024-12-16 Git常用操作
- 2024-12-16 git清除历史纪录
- 2024-12-16 如何使用 Git 工作树(Worktrees)来提高工作效率
- 2024-12-16 我写一个git用法吧
- 2024-12-16 一篇文章明白Git的14条常用命令
- 2024-12-16 掌握git命令,图解一目了然
- 2024-12-16 Git 版本控制:团队协作与项目管理的利器
- 最近发表
- 标签列表
-
- 向日葵无法连接服务器 (32)
- git.exe (33)
- vscode更新 (34)
- dev c (33)
- git ignore命令 (32)
- gitlab提交代码步骤 (37)
- java update (36)
- vue debug (34)
- vue blur (32)
- vscode导入vue项目 (33)
- vue chart (32)
- vue cms (32)
- 大雅数据库 (34)
- 技术迭代 (37)
- 同一局域网 (33)
- github拒绝连接 (33)
- vscode php插件 (32)
- vue注释快捷键 (32)
- linux ssr (33)
- 微端服务器 (35)
- 导航猫 (32)
- 获取当前时间年月日 (33)
- stp软件 (33)
- http下载文件 (33)
- linux bt下载 (33)