Author: Tian Yawen
link: https://www.zhihu.com/question/27712995/answer/39946123
Source: know almost
copyrighted by the author. For commercial reprints, please contact the author for authorization, and for non-commercial reprints, please indicate the source.
Your code repository (repository) can be stored on your computer, and you can also host the code repository on a Github server. By default, origin points to the version of your local code base hosted on Github. Let’s assume that you first created a Repository on github called repository. Assuming your Github ID is user1, the link to your code base at this time is
https://github.com/user1/repository
If you type in the terminal
git clone https://github.com/user1/repository
Then git will copy a copy of the code library hosted on github locally. At this time, you cd to the repository and enter
git remote -v
You will see the console output
origin https://github.com/user1/repository.git (fetch)
origin https://github.com/user1/repository.git (push)
也就是说git为你默认创建了一个指向远端代码库的origin
(Because you cloned from this address). Here we want to contact the commands we often use git remote add origin 你的GitHub上的地址
. In fact, this is a manual alias for the address of your remote warehouse.
Suppose there is now a user user2 that forks your repository, then his code base link looks like this
https://github.com/user2/repository
If he followed this clone and typed git remote -v in his console,
what he would see is
origin https://github.com/user2/repository.git (fetch)
origin https://github.com/user2/repository.git (push)
You can see that origin
the location pointed to is the address of the remote code base of user2. If user2 wants to add a remote point to your code base, he can enter it in the console
git remote add upstream https://github.com/user1/repository.git
Then enter git remote -v again and the output will become
origin https://github.com/user2/repository.git (fetch)
origin https://github.com/user2/repository.git (push)
upstream https://github.com/user1/repository.git (fetch)
upstream https://github.com/user1/repository.git (push)
Added an upstream pointing to the user1 code base, which is the previous naming of the pointing location. In summary, as the name suggests, origin is a name. It is a tag that git creates by default to point to this remote code base when you clone a code base hosted on Github. @陈肖恩's answer is not accurate origin指向的是repository,master只是这个repository中默认创建的第一个branch
.当你git push的时候因为origin和master都是默认创建的,所以可以这样省略,但是这个是bad practice,因为当你换一个branch再git push的时候,有时候就纠结了