本文翻译自:What is “origin” in Git?
When I run: 当我跑:
git push origin branchname
What exactly is origin
and why do I have to type it before the branch name? 究竟是什么origin
,为什么我必须在分支名称之前键入它?
#1楼
参考:https://stackoom.com/question/dz3Z/Git中的-起源-是什么
#2楼
origin
is not the remote repository name. origin
不是远程存储库名称。 It is rather a local alias set as a key in place of the remote repository URL. 它是一个本地别名集,作为代替远程存储库URL的密钥。
It avoids the user having to type the whole remote URL when prompting a push. 它避免了用户在提示推送时必须键入整个远程URL。
This name is set by default and for convention by Git when cloning from a remote for the first time. 默认情况下,此名称是设置的,当第一次从远程克隆时,由Git设置。
This alias name is not hard coded and could be changed using following command prompt: 此别名不是硬编码的,可以使用以下命令提示符进行更改:
git remote rename origin mynewalias
Take a look at http://git-scm.com/docs/git-remote for further clarifications. 请查看http://git-scm.com/docs/git-remote以获取进一步说明。
#3楼
I was also confused by this, and below is what I have learned. 我也对此感到困惑,以下是我所学到的。
When you clone a repository, for example from GitHub: 克隆存储库时,例如从GitHub克隆:
origin
is the alias for the URL from which you cloned the repository.origin
是克隆存储库的URL的别名。 Note that you can change this alias. 请注意,您可以更改此别名。There is one
master
branch in the remote repository (aliased byorigin
). 远程存储库中有一个master
分支(按origin
别名)。 There is also anothermaster
branch created locally. 还有另一个本地创建的master
分支。
Further information can be found from this SO question: Git branching: master vs. origin/master vs. remotes/origin/master 更多信息可以从这个SO问题中找到: Git分支:master与origin / master vs. remotes / origin / master
#4楼
When you clone a repository with git clone
, it automatically creates a remote connection called origin
pointing back to the cloned repository. 使用git clone
克隆存储库时,它会自动创建一个名为origin
的远程连接,指向克隆的存储库。 This is useful for developers creating a local copy of a central repository since it provides an easy way to pull upstream changes or publish local commits. 这对于创建中央存储库的本地副本的开发人员非常有用,因为它提供了一种简单的方法来提取上游更改或发布本地提交。 This behavior is also why most Git-based projects call their central repository origin. 这种行为也是大多数基于Git的项目调用其中央存储库源的原因。
#5楼
Simple! 简单! "origin" is just what you nicknamed your remote repository when you ran a command like this: 当你运行这样的命令时,“origin”就是你昵称你的远程存储库:
git remote add origin git@github.com:USERNAME/REPOSITORY-NAME.git
From then on Git knows that "origin" points to that specific repository (in this case a GitHub repository). 从那时起,Git知道“origin”指向该特定存储库(在本例中为GitHub存储库)。 You could have named it "github" or "repo" or whatever you wanted. 你可以将它命名为“github”或“repo”或任何你想要的东西。
#6楼
The best answer here: 最好的答案在这里:
https://www.git-tower.com/learn/git/glossary/origin 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. 在Git中,“origin”是最初克隆项目的远程存储库的简写名称。 More precisely, it is used instead of that original repository's URL - and thereby makes referencing much easier. 更准确地说,它被用来代替原始存储库的URL - 从而使引用更容易。