本篇內(nèi)容介紹了“怎么將代碼同時提交到Github和碼云Gitee上”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比楊浦網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式楊浦網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋楊浦地區(qū)。費用合理售后完善,10余年實體公司更值得信賴。
本文目錄:
多個遠程倉庫在項目中很少使用,但Git本身是支持的。
那讓我們跟著一個案例來溫習(xí)一下Git命令吧:案例代碼已經(jīng)在Github中托管了,現(xiàn)在要增加Gitee遠程倉庫。
先來查看下當(dāng)前項目的遠程倉庫
git remote
不出意外,應(yīng)該會輸出:
origin
這個origin
就是一個指向遠程倉庫的名稱,是你在clone
時 git
為你默認創(chuàng)建的。
可以通過命令查看origin
指向的遠程倉庫地址:
git remote -v
輸出結(jié)果:
origin https://github.com/gozhuyinglong/blog-demos.git (fetch) origin https://github.com/gozhuyinglong/blog-demos.git (push)
該命令會顯示讀寫遠程倉庫的名稱和地址,我這里指向的是Github。
既然這個地址是Github,為了好識別,就將名稱改成 github 吧。輸入命令: git remote rename <old_remote> <new_remote>
git remote rename origin github
輸入查看遠程倉庫命令,驗證下是否成功,輸出結(jié)果:
github https://github.com/gozhuyinglong/blog-demos.git (fetch) github https://github.com/gozhuyinglong/blog-demos.git (push)
成功!
下面我們再添加Gitee上的遠程倉庫,首先在Gitee上創(chuàng)建一個空的倉庫,名稱與Github上相同。
然后在【克隆/下載】處復(fù)制地址。
輸出添加遠程倉庫命令: git remote add <remote> <url>
git remote add gitee https://gitee.com/gozhuyinglong/blog-demos.git
再來驗證下是否成功,輸出結(jié)果:
gitee https://gitee.com/gozhuyinglong/blog-demos.git (fetch) gitee https://gitee.com/gozhuyinglong/blog-demos.git (push) github https://github.com/gozhuyinglong/blog-demos.git (fetch) github https://github.com/gozhuyinglong/blog-demos.git (push)
成功!
有了多個遠程倉庫,推送和拉取再也不能像以前那樣git push
和git pull
了,必須得加上遠程倉庫的名稱,以識別操作的是哪個遠程倉庫。命令如下: git push <remote> <branch>
、git pull <remote> <branch>
:
git push github main git pull github main git push gitee main git pull gitee main
如果不想每次操作都帶著分支,需要將本地分支與遠程分支進行關(guān)聯(lián): git branch --set-upstream-to=<remote>/<remote_branch> <local_branch>
git branch --set-upstream-to=gitee/main main
關(guān)聯(lián)后就可以不指定分支了
git push github git pull github git push gitee git pull gitee
如果想要移除一個遠程倉庫,可以使用下面命令: git remote remove <remote>
或git remote rm <remote>
git remote remove gitee
執(zhí)行移除遠程倉庫后,該倉庫在本地的所有分支與配置信息也會一并刪除。
在執(zhí)行上面操作當(dāng)然不是一帆風(fēng)順的,如果你遇到一些錯誤,這里可能有你想要的答案。
當(dāng)在拉取時報下面錯誤:
You asked to pull from the remote 'gitee', but did not specify a branch. Because this is not the default configured remote for your current branch, you must specify a branch on the command line.
表示本地分支與遠程分支未做關(guān)聯(lián),進行關(guān)聯(lián)一下即可,執(zhí)行下面命令: git branch --set-upstream-to=<remote>/<remote_branch> <your_branch>
git branch --set-upstream-to=gitee/main main
當(dāng)執(zhí)行推送操作時,提示下面信息:
remote: You do not have permission push to this repository fatal: unable to access 'https://gitee.com/gozhuyinglong/blog-demos.git/': The requested URL returned error: 403
表示沒有遠程倉庫的權(quán)限,應(yīng)該首先查看遠程倉庫是否公開,再檢查本地賬號和密碼是否正確。
登錄Gitee,檢查該代碼庫是否公司。若未公開,則設(shè)置為公開。
打開控制面板,點擊【用戶賬戶】
再點擊【管理Windows憑據(jù)】
找到你的賬號,修改賬號和密碼即可。
你也可以直接將Windows憑據(jù)刪掉,當(dāng)執(zhí)行推送命令后,會彈出Windows安全中心登錄框。
輸入你的賬號或密碼就可以了。
如果無法彈出Windows安全中心登錄框,則將其卸載掉,執(zhí)行下面命令:
git credential-manager uninstall
再重新下載并安裝,下載地址: https://github.com/microsoft/Git-Credential-Manager-for-Windows/releases
如下圖所示,當(dāng)你每次push
代碼時,都會彈出下面登錄框。
我們可以將遠程地址改為SSH地址:
移除現(xiàn)在的github地址,重新添加ssh地址,具體代碼參照上文。
添加好地址后,還需要在github上設(shè)置SSH Key
輸入下面命令來生成SSH Key,雙引號內(nèi)填寫你的登錄郵箱地址
ssh-keygen -t rsa -C "xxxxx@xxxxx.com"
如果彈出下面提示,直接回車即可。(若已存在,會提示是否替換,輸入Y再回車)
會在你的磁盤目錄【C:\Users\你的用戶名.ssh\】中生成公鑰,將文件【id_rsa.pub】中的內(nèi)存拷貝。
打開github的【SSH and GPG keys】頁面,添加即可:
“怎么將代碼同時提交到Github和碼云Gitee上”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
網(wǎng)頁名稱:怎么將代碼同時提交到Github和碼云Gitee上
標(biāo)題網(wǎng)址:http://m.2m8n56k.cn/article28/jdsdcp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、網(wǎng)站排名、做網(wǎng)站、網(wǎng)站導(dǎo)航、品牌網(wǎng)站設(shè)計、手機網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)