Git管理多個遠端倉庫(GitHub和Coding)
阿新 • • 發佈:2019-01-25
兩個空程式碼倉庫
如果是兩個倉庫都是空的,就直接在 .git/config 中新增遠端地址
[remote "origin"]
url = https://github.com/younglaker/octjs.git
url = https://git.coding.net/laker/octjs.git #新增新地址
fetch = +refs/heads/*:refs/remotes/origin/*
地址是配好了,但是還要注意分支一致。我這裡都用master,就不會有問題。
非空程式碼倉庫
假設Github中使用了一段時間,想在Coding裡備份一個,要想把兩邊倉庫同步到一致的狀態。
線到Coding新建倉庫,獲得地址後, .git/config 中新增Coding的遠端地址,這裡我命名為coding:
[remote "origin"]
url = https://github.com/younglaker/octjs.git
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "coding"] #新增coding遠端
url = https://git.coding.net/laker/octjs.git #遠端地址
fetch = +refs/heads/*:refs/remotes/coding/* #注意修改遠端名
使用Git GUI 獲取 Coding上的資訊,你也可以使用命令列完成一下操作:
合併:
推送,記得選Coding遠端:
然後再修改 .git/config ,吧Coding也用origin遠端名,下次就只用 git push 就可以推送到兩邊了。重啟 Git GUI 也只剩一個遠端了:
[remote "origin"]
url = https://github.com/younglaker/octjs.git
url = https://git.coding.net/laker/octjs.git
fetch = +refs/heads/*:refs/remotes/origin/*
Github 不為空,Coding為新建專案
那就在Coding新建專案時匯入Github專案,本地git配置改為:
[remote "origin"]
url = https://github.com/younglaker/octjs.git
url = https://git.coding.net/laker/octjs.git
fetch = +refs/heads/*:refs/remotes/origin/*