What is “origin” in Git?
当我跑步时:
1 | git push origin branchname |
通过做
1 | git push origin branchname |
您的意思是推送到
远程只是存储库URL的别名。您可以使用
1 | git remote -v |
号
在
1 | git push [email protected]:git/git.git master |
它避免了用户在提示推送时必须键入整个远程URL。
这个名称是默认设置的,并且在第一次从远程克隆时由git进行约定。
此别名不是硬编码的,可以使用以下命令提示进行更改:
1 | git remote rename origin mynewalias |
。
请访问http://git-scm.com/docs/git-remote了解进一步的说明。
Git有"远程"的概念,它只是指向存储库其他副本的URL。克隆另一个存储库时,git会自动创建一个名为"origin"的远程存储库并指向它。
您可以通过键入
简单!"当您运行这样的命令时,"origin"就是您所昵称的远程存储库:
1 | git remote add origin [email protected]:USERNAME/REPOSITORY-NAME.git |
从那时起,Git就知道"origin"指向特定的存储库(在本例中是GitHub存储库)。你可以把它命名为"github"或"repo"或你想要的任何东西。
我也对这件事感到困惑,下面是我学到的。
克隆存储库时,例如从Github:
origin 是从中克隆存储库的URL的别名。请注意,您可以更改此别名。远程存储库中有一个
master 分支(别名为origin )。还有一个在本地创建的master 分支。
更多信息可以从这个问题中找到:git分支:master vs.origin/master vs.remotes/origin/master
使用
最好的答案是:
https://www.git-tower.com/learn/git/glossary/origin
In Git,"origin" is a shorthand name for the remote repository that a
project was originally cloned from. More precisely, it is used instead
of that original repository's URL - and thereby makes referencing much
easier.
号
另一个答案是,
所有URL都是URI,但并非所有URI都是URL。
简而言之,当你输入
就像变量一样,你可以随意命名它(如
来自https://www.git-tower.com/learn/git/glossary/origin:
In Git,"origin" is a shorthand name for the remote repository that a project was originally cloned from. More precisely, it is used instead of that original repository's URL - and thereby makes referencing much easier.
Note that origin is by no means a"magical" name, but just a standard convention. Although it makes sense to leave this convention untouched, you could perfectly rename it without losing any functionality.
In the following example, the URL parameter to the"clone" command becomes the"origin" for the cloned local repository:
1 git clone https://github.com/gittower/git-crash-course.git
号