首頁  >  文章  >  開發工具  >  git中origin是什麼意思

git中origin是什麼意思

WBOY
WBOY原創
2022-01-07 15:36:5816469瀏覽

在git中,origin的意思是指“遠端倉庫”,就是遠端倉庫連結的別名,是在clone一個託管在Github上程式碼庫時,git預設建立的指向這個遠端程式碼庫的標籤,origin指向的就是本地的程式碼庫託管在Github上的版本。

git中origin是什麼意思

本文操作環境:Windows10系統、Git2.30.0版、Dell G3電腦。

git中origin是什麼意思

你的程式碼庫(repository)可以存放在你的電腦裡,同時你也可以把程式碼庫託管到Github的伺服器上。

在預設情況下,origin指向的就是你本地的程式碼庫託管在Github上的版本。

我們假設你先在github上建立了一個Repository,叫做repository,假設你的Github ID是user1,這個時候指向你的程式碼庫的連結是

https://github.com/user1/repository

如果你在terminal裡輸入

git clone https://github.com/user1/repository

那麼git就會在本地拷貝一份託管在github上的程式碼庫

這時候你cd到repository

然後輸入

git remote -v

你會看到控制台輸出

origin https://github.com/user1/repository.git (fetch)
origin https://github.com/user1/repository.git (push)

也就是說git為你預設創建了一個指向遠端程式碼庫的origin(因為你是從這個位址clone下來的)

再假設現在有一個使用者user2 fork了你個repository,那麼他的程式碼庫連結就是這個樣子

https://github.com/user2/repository

如果他也照著這個clone一把,然後在他的控制台裡輸入

git remote -v

他會看的是

origin https://github.com/user2/repository.git (fetch)
origin https://github.com/user2/repository.git (push)

可以看的origin指向的位置是user2的的遠端程式碼庫

這個時候,如果user2想要加一個遠端指向你的程式碼庫,他可以在控制台輸入

git remote add upstream https://github.com/user1/repository.git

然後再輸入一次git remote -v

#輸出結果就會變成

origin https://github.com/user2/repository.git (fetch)
origin https://github.com/user2/repository.git (push)
upstream https://github.com/user1/repository.git (push)
upstream https://github.com/user1/repository.git (push)

增加了指向user1程式碼庫的upstream ,也就是之前對指向位置的命名。

總結來講,顧名思義,origin就是一個名字,它是在你clone一個託管在Github上程式碼庫時,git為你預設創建的指向這個遠端程式碼庫的標籤,

#推薦學習:《Git教學

以上是git中origin是什麼意思的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn