Git 中的“起源”是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9529497/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:05:48  来源:igfitidea点击:

What is "origin" in Git?

git

提问by enchance

When I run:

当我运行时:

git push origin branchname

What exactly is originand why do I have to type it before the branch name?

究竟是什么origin,为什么我必须在分支名称之前输入它?

采纳答案by doelleri

originis an aliason your systemfor a particular remote repository. It's not actually a property of that repository.

origin系统上特定远程存储库的别名。它实际上不是该存储库的属性。

By doing

通过做

git push origin branchname

you're saying to push to the originrepository. There's no requirement to name the remote repository origin: in fact the same repository could have a different alias for another developer.

你说要推送到origin存储库。不需要命名远程存储库origin:事实上,同一个存储库可以为另一个开发人员使用不同的别名。

Remotes are simply an aliasthat store the URL of repositories. You can see what URL belongs to each remote by using

Remotes 只是一个别名,用于存储存储库的 URL。您可以使用以下命令查看属于每个遥控器的 URL

git remote -v

In the pushcommand, you can use remotesor you can simply use a URLdirectly. An example that uses the URL:

push命令中,您可以使用遥控器,也可以直接使用URL。使用 URL 的示例:

git push [email protected]:git/git.git master

回答by Antoine Meltzheim

originis notthe remote repository name. It is rather a local aliasset as a key in place of the remote repository URL.

origin不是远程仓库名。它是一个本地别名,设置为代替远程存储库 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-remotefor further clarifications.

查看http://git-scm.com/docs/git-remote以获得进一步说明。

回答by Jason Malinowski

Git has the concept of "remotes", which are simply URLs to other copies of your repository. When you clone another repository, Git automatically creates a remote named "origin" and points to it.

Git 有“远程”的概念,它只是指向存储库其他副本的 URL。当您克隆另一个存储库时,Git 会自动创建一个名为“origin”的远程并指向它。

You can see more information about the remote by typing git remote show origin.

您可以通过键入 来查看有关遥控器的更多信息git remote show origin

回答by Jude Calimbas

originis the default aliasto the URL of your remote repository.

origin是远程存储库 URL的默认别名

回答by Trev14

Simple! "origin" is just what you nicknamed your remote repository when you ran a command like this:

简单的!当您运行这样的命令时,“origin”就是您为远程存储库命名的昵称:

git remote add origin [email protected]:USERNAME/REPOSITORY-NAME.git

From then on Git knows that "origin" points to that specific repository (in this case a GitHub repository). You could have named it "github" or "repo" or whatever you wanted.

从那时起,Git 知道“origin”指向该特定存储库(在本例中为 GitHub 存储库)。您可以将其命名为“github”或“repo”或您想要的任何名称。

回答by umesh prakash bapat

I was also confused by this, and below is what I have learned.

我也对此感到困惑,以下是我所学到的。

When you clone a repository, for example from GitHub:

当您克隆存储库时,例如从 GitHub:

  • originis the alias for the URL from which you cloned the repository. Note that you can change this alias.

  • There is one masterbranch in the remote repository (aliased by origin). There is also another masterbranch created locally.

  • origin是您从中克隆存储库的 URL 的别名。请注意,您可以更改此别名。

  • master远程存储库中有一个分支(别名为origin)。还有一个master本地创建的分支。

Further information can be found from this SO question: Git branching: master vs. origin/master vs. remotes/origin/master

可以从这个 SO 问题中找到更多信息:Git branching: master vs. origin/master vs. remotes/origin/master

回答by Volodymyr

When you clone a repository with git clone, it automatically creates a remote connection called originpointing back to the cloned repository. 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 clone,它会自动创建一个远程连接,称为origin指向克隆的存储库。这对于创建中央存储库的本地副本的开发人员很有用,因为它提供了一种简单的方法来拉取上游更改或发布本地提交。这种行为也是大多数基于 Git 的项目称其为中央存储库来源的原因。

回答by Alexander Shapkin

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. More precisely, it is used instead of that original repository's URL - and thereby makes referencing much easier.

在 Git 中,“origin”是最初克隆项目的远程存储库的简写名称。更准确地说,它被用来代替原始存储库的 URL - 从而使引用变得更加容易。

回答by Deeksha Sharma

From 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. 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:

git clone https://github.com/gittower/git-crash-course.git

在 Git 中,“origin”是最初克隆项目的远程存储库的简写名称。更准确地说,它被用来代替原始存储库的 URL - 从而使引用变得更加容易。

请注意,origin 绝不是一个“神奇”的名字,而只是一个标准约定。尽管保持此约定不变是有意义的,但您可以完美地重命名它而不会丢失任何功能。

在以下示例中,“clone”命令的 URL 参数成为克隆的本地存储库的“来源”:

git clone https://github.com/gittower/git-crash-course.git

回答by Andy Lindsay

The other answers say that originis an alias for the URLof a remote repository which is not entirely accurate. It should be noted that an address that starts with httpis a URL while one that starts with git@is a URIor Universal Resource Identifier.

其他答案说这是不完全准确的远程存储库URLorigin的别名。需要说明的是,以 开头的地址是 URL ,以 开头的地址是URI或通用资源标识符。httpgit@

All URLs are URIs, but not all URIs are URLs.

所有 URL 都是 URI,但并非所有 URI 都是 URL。

In short, when you type git remote add origin <URI>you are telling your local git that whenever you use the word originyou actually mean the URI that you specified. Think of it like a variable holding a value.

简而言之,当您键入时,git remote add origin <URI>您是在告诉本地 git,每当您使用该词时,origin您实际上指的是您指定的 URI。把它想象成一个保存值的变量。

And just like a variable, you can name it whatever you want (eg. github, heroku, destination, etc).

就如同一个变量,你可以将其命名任何你想要的(如githubherokudestination,等)。