Git 里面的 origin 到底代表啥意思?(转帖)
作者:田雅文 链接:https://www.zhihu.com/question/27712995/answer/39946123 来源:知乎 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
你的代码库(repository)可以存放在你的电脑里,同时你也可以把代码库托管到Github的服务器上。
在默认情况下,origin指向的就是你本地的代码库托管在Github上的版本。
我们假设你首先在github上创建了一个Repository,叫做repository,假设你的Github ID是user1,这个时候指向你的代码库的链接是https://github.com/user1/repository
git clone https://github.com/user1/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
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为你默认创建的指向这个远程代码库的标签, 的答案并不准确,origin指向的是repository,master只是这个repository中默认创建的第一个branch。当你git push的时候因为origin和master都是默认创建的,所以可以这样省略,但是这个是bad practice,因为当你换一个branch再git push的时候,有时候就纠结了--------------------
楼上的太啰嗦。 直接把它翻译成“本体”就好了。 看看origin 本体 git还是一个指令是clone就是克隆。
一个项目的刚开始,在服务器端,建立一个 origin,就是本体 然后在本体基础上 clone到本地,就是克隆,也可以分支。 clone在本地的,叫master,有种本地的 本体的味道,因为本地的还可以根据master进行分支,或者被别人再cloneposted on 2017-09-14 10:10 carson.qian 阅读(214) 评论(0) 收藏 举报
浙公网安备 33010602011771号