标签:origin git coding myname project merge 添加 https 远程
这几天项目中遇到一个git场景:
项目仓库保存在以下三个地方:
- GitHub
- GitLab
- Coding
由于项目是我在开发维护,所以这三个仓库地址一直都是在同一个远程仓库origin下,三处代码时刻保持一致。
>>> git remote -v
origin https://github.com/myname/project.git (fetch)
origin https://github.com/myname/project.git (push)
origin http://10.8.15.49:9091/myname/project.git (push)
origin https://e.coding.net/myname/01/project.git (push)
但最近项目代码需要进行一处修改,需要同事来做,同事不会使用Git,所以就直接让他在Coding上进行修改了。但如何把他做出的修改更新到GitHub和GitLab上,使三处代码继续保持一致呢?
首先,添加新的远程仓库
>>> git remote add coding https://e.coding.net/myname/01/project.git
>>> git remote -v
coding https://e.coding.net/myname/01/project.git (fetch)
coding https://e.coding.net/myname/01/project.git (push)
origin https://github.com/myname/project.git (fetch)
origin https://github.com/myname/project.git (push)
origin http://10.8.15.49:9091/myname/project.git (push)
origin https://e.coding.net/myname/01/project.git (push)
>>> cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/myname/project.git
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://10.8.15.49:9091/myname/project.git
url = https://e.coding.net/myname/01/project.git
[branch "main"]
remote = origin
merge = refs/heads/main
[branch "1.4"]
remote = origin
merge = refs/heads/1.4
[remote "coding"]
url = https://e.coding.net/myname/01/project.git
fetch = +refs/heads/*:refs/remotes/coding/*
可以看到已经多出coding远程仓库了
然后,使用fetch更新一下
>>> git fetch coding
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 9 (delta 7), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), 810 bytes | 67.00 KiB/s, done.
From https://e.coding.net/myname/01/project
* [new branch] 1.4 -> coding/1.4
* [new branch] main -> coding/main
然后将代码合并,上传
>>> git checkout 1.4
>>> git merge coding/1.4
>>> git push origin 1.4
大功告成!!!
之前一直都是手动修改.git/config文件来添加删除远程仓库地址,但最近才知道git提供有专门的命令
>>> git remote set-url origin --add https://e.coding.net/myname/01/project.git
效果就是会在.git/config中的origin远程仓库下添加一个url
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/MacwinWin/wxapp_api.git
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://10.8.15.49:9091/gaoxiang/wxapp_api.git
url = https://e.coding.net/xlxdsj/01/wxapp_api.git
[branch "main"]
remote = origin
merge = refs/heads/main
[branch "1.4"]
remote = origin
merge = refs/heads/1.4
参考:
https://stackoverflow.com/a/12795747/7151777
https://www.jianshu.com/p/4cd46619b3a5
https://stackoverflow.com/a/16608774/7151777
标签:origin,git,coding,myname,project,merge,添加,https,远程 来源: https://blog.csdn.net/MacwinWin/article/details/117385547
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。