你的代碼庫(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為你默認創建的指向這個遠程代碼庫的標簽
轉載:https://www.zhihu.com/question/27712995/answer/39946123