git同時提交到2個倉庫gitee github
阿新 • • 發佈:2022-04-20
本文由 簡悅 SimpRead 轉碼, 原文地址 www.csdn.net
csdn已為您找到關於git 同時提交多個倉庫相關內容,包含git 同時提交多個倉庫相關文件程式碼介紹、相關教程視訊課程,以及相關git 同時提交多個倉庫問答內容。為您解決當下相關問題,如果想了解更詳細git 同時提交多個倉庫內容,請點選詳情連結進行了解,或者註冊賬號與客服人員聯絡給您提供相關內容的幫助,以下是為您準備的相關內容。
1.進入專案根目錄
2.點選檢視,顯示隱藏資料夾
出現git資料夾
3.進入.git資料夾
4.
4.編輯config
原檔案
修改後
程式碼如下
[core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true [submodule] active = . [remote "origin"] url = https://gitee.com/stylesmile/snow.git fetch = +refs/heads/*:refs/remotes/origin/* url = https://github.com/stylesmile/snow.git [branch "master"] remote = origin merge = refs/heads/master [remote "github"] url = https://github.com/stylesmile/snow.git fetch = +refs/heads/*:refs/remotes/gitee/* tagopt = --no-tags
再次push ,就會同時提交到2個倉庫
有時候一個專案,希望既提交到 oschina 又提交到公司內網的 gitlab,或者是 github 什麼的。
使用 git remote -v 檢視當前 git 的遠端倉庫。
新增一個遠端倉庫
git remote add <name> <url-of-remote> ###<name>自己起個名字,預設是oringn,那麼新增的第二個我們可以叫oschinaxxx,這樣比較方便記憶是哪個源,<url of remote>是第二個git倉庫的url連結。
此時我們還不能就立即使用
git push oschinaxxx master這樣直接提交了,git會提示讓我們先pull, 此時
git pull oschinaxxx master 還會報錯,非關聯的倉庫不能拉下來。
使用如下命令,新增--allow-unrelated-histories引數
git pull oschinaxxx master --allow-unrelated-histories解決之。
之後就可以愉快的給遠端倉庫push了
git push <name of remote repository> <name of branch>,就可以push到相應的倉庫了。也可以在pycahrm上直接完成這個。
可以做成一個bat批處理指令碼,來執行push
git diff --name-only HEAD~1 HEAD git pull ocmtdcs master git pull origin master git push ocmtdcs master git push origin master pause