git 命令中的“origin”和“remote”有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38837705/
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
What is the difference between 'origin' and 'remote' in git commands?
提问by YCode
In git lingo, are origin
and remote
the same thing? Or does origin
refer to the local directory?
在 git 行话中,origin
和remote
是一样的吗?还是origin
参考本地目录?
In the case of git push -u origin master
: Which of the following interpretation is correct?
在以下情况下git push -u origin master
:以下哪个解释是正确的?
- "push everything upstream to the remote repo called 'origin' and its branch 'master'"
- "push everything from the local originating repo called 'origin' to the upstream 'master' branch"
- “将所有内容推送到名为‘origin’的远程仓库及其分支‘master’”
- “将所有内容从名为 'origin' 的本地原始 repo 推送到上游的 'master' 分支”
Appreciate any clarification!
感谢任何澄清!
The answers to my question clarified two issues for me:
我的问题的答案为我澄清了两个问题:
origin
refers to the remote repo, rather than the local cloned copy of the remote repo. This is not clear when one reads thatorigin
is an alias ofremote
and is created at the time ofgit clone
origin
refers to the remote repo ingit push -u origin master
because local copies of the repo are implied and "rarely referenced".
origin
指的是远程仓库,而不是远程仓库的本地克隆副本。当读取origin
是 的别名remote
并在其创建时,这一点尚不清楚git clone
origin
指的是远程存储库,git push -u origin master
因为存储库的本地副本是隐含的并且“很少引用”。
采纳答案by Deltics
In git lingo origin
is just the default name for a remote from which a repo was originally cloned. It might equally have been called source
or remote1
or just remote
.
在 git lingoorigin
中只是最初克隆 repo 的远程的默认名称。它可能同样被称为source
orremote1
或 just remote
。
Remember that git
is a peer-to-peer, distributed system, not one with any built-in notion of client/server, master/slave, parent/child relationships (though these might be imposed upon it by a user in a particular scenario).
请记住,这git
是一个点对点的分布式系统,而不是具有任何内置的客户端/服务器、主/从、父/子关系概念的系统(尽管这些可能由用户在特定场景中强加给它) .
All remotes are equal. origin
is simply (and literally) the first among those equals (for a cloned repo). :)
所有遥控器都是平等的。 origin
简单地(并且字面上)是这些相等中的第一个(对于克隆的回购)。:)
And as Jan points out in the comments, the name associated with each remote is intended for your convenience. If you find that origin
does not really work for you then you can change it.
正如 Jan 在评论中指出的那样,与每个遥控器相关联的名称是为了您的方便。如果您发现这origin
对您不起作用,那么您可以更改它。
As for your interpretations of the push
statement, your first is the closest to being correct but the push command as written will push the local master
branch to the master
branch on the remote identified by the (locally configured) name origin
.
至于您对push
语句的解释,您的第一个最接近正确,但是所写的 push 命令会将本地master
分支推送到master
由(本地配置的) name 标识的远程分支origin
。
If there is no master
branch in the remote then one will be created.
如果master
远程中没有分支,则将创建一个。
Full details of the push command and the flags, options etc are of course in the docs.
push 命令和标志、选项等的完整细节当然在 docs 中。
You rarely (if ever) refer to the 'local' repo explicitly since your operations are performed in the context of a repo.
您很少(如果有的话)显式地引用“本地”存储库,因为您的操作是在存储库的上下文中执行的。
回答by Sebastian Lenartowicz
No, they don't mean the same thing.
不,它们不是同一个意思。
remote
, in git
-speak, refers to any remote repository, such as your GitHub or another git
server.
remote
,git
换句话说,指的是任何远程存储库,例如您的 GitHub 或其他git
服务器。
origin
is the, by convention, default remote name in git
. When you do a git clone <url>
, <url>
is automatically added to your local repo under the name origin
. You can, of course, add other remotes under different names using git remote add
.
origin
按照惯例,是git
. 当您执行 a 时git clone <url>
,<url>
会自动添加到您本地存储库的名称下origin
。当然,您可以使用git remote add
.
When you do git push -u origin master
, what it means is "push everything from my local master to the remote named origin
". The structure of this command is, of course, more general - the more general form is git push -u <remote> <branch>
, which will push the branch named branch
to the designated remote, creating it at the far end if the remote doesn't already have it (that's what the -u
flag does).
当你这样做时git push -u origin master
,它的意思是“将所有东西从我的本地主服务器推送到名为远程的origin
”。当然,这个命令的结构更通用 - 更通用的形式是git push -u <remote> <branch>
,它将把命名的分支推branch
送到指定的远程,如果远程还没有它,则在远端创建它(这就是-u
标志做)。
As a further addendum, git push
, by default, will push the current branch to origin
, corresponding to git push origin <current-branch>
.
作为进一步的补充,git push
默认情况下,会将当前分支推送到origin
,对应于git push origin <current-branch>
。
回答by Jeff Puckett
You can have multiple remotes, each with a different name - such as the default "origin"
您可以有多个遥控器,每个遥控器都有不同的名称 - 例如默认的“来源”
Your question makes the assumption that you currently have the master branch checked out.
您的问题假设您目前已检出主分支。
git push -u origin master
Push the local branch named master to the "origin" remote as the branch named master. The -u flag tells local git to track that remote branch as upstream to your local branch.
将名为 master 的本地分支作为名为 master 的分支推送到“源”远程。-u 标志告诉本地 git 将远程分支作为本地分支的上游进行跟踪。
回答by torek
A remoteis just a word: a name to use to identify some other Git repository somewhere.
一个远程只是一句话:一个名字用来标识一些其他Git仓库的某个地方。
The string origin
is the default name of the (singular) remote that git clone
puts in automatically, when you clone from some other ("origin"-al) Git repository. You can choose some other name, and/or add more remotes. Each remote has, at the least, a URL, which is where the other repository is to be found.
当您从其他(“origin”-al)Git 存储库克隆时origin
,该字符串是git clone
自动放入的(单一)远程的默认名称。您可以选择其他名称,和/或添加更多遥控器。每个远程都至少有一个 URL,这是可以找到另一个存储库的位置。
For git push
, the third word—adjust this number if needed, if you add various flags; in this case you added -u
so now it's the fourth word—is normally the name of some remote.
对于git push
,第三个字——如果需要,调整这个数字,如果你添加了各种标志;在这种情况下,您添加了-u
所以现在它是第四个词 - 通常是某个遥控器的名称。
The remaining words are all refspecs, which can be summarized (though not 100% accurately ... in fact, less than 50% accurately, depending on how you count :-) ) as a pair of branch names separated by a colon.
剩下的词都是refspecs,可以概括为一对用冒号分隔的分支名称(虽然不是 100% 准确……事实上,准确度不到 50%,这取决于您如何计算 :-) )。
If you write just one branch name like master
, Git takes that to mean "use (part of) the upstream if one is set, otherwise use the same name after the colon." Usually the upstream, if set, has the same basic name, so master
usually winds up meaning master:master
. Git sends them—the Git at the remote's URL—commits found on yourbranch (the name on the left), and then asks them to set theirbranch (the name on the right) to the same tip commit you just pushed for that branch.
如果你只写一个分支名称,如master
,Git 认为它意味着“如果设置了上游,则使用(部分)上游,否则在冒号后使用相同的名称。” 通常上游,如果设置,具有相同的基本名称,所以master
通常结束意义master:master
。Git 发送它们——远程 URL 上的 Git——提交在您的分支(左侧的名称)上找到,然后要求他们将他们的分支(右侧的名称)设置为您刚刚为该分支推送的相同提示提交.
If you don't put in any refspecs, Git's default depends on your Git version. Since Git version 2.0, the default is to push your current branchto a branch of the same name on the remote.
如果你没有输入任何 refspecs,Git 的默认值取决于你的 Git 版本。从 Git 2.0 版本开始,默认是将当前分支推送到远程的同名分支。
The -u
flag tells git push
that, if the push succeeds, it should setthe upstream for the branch you just pushed.
该-u
标志git push
表明,如果推送成功,它应该为您刚刚推送的分支设置上游。
The upstreamof a branch comes in two parts: the name of a remote, and the name of a branch on that remote. Since you gave git push
both items—the name of the remote was origin
, and the branch was the second (post-colon) master
from the implied master:master
from master
—this will, if it succeeds, set the upstream for master
to origin/master
.
分支的上游分为两部分:远程名称和远程分支的名称。既然你给了git push
这两个项目,在远程的名字origin
,和分支是第二(后冒号)master
从隐含master:master
的master
-这个意愿,如果成功,将上游的master
来origin/master
。
(Edit: you might, quite legitimately, wonder where the /
came from in the upstreamsetting of origin/master
. That's partly a historical artifact. Unfortunately, it leads to huge amounts of confusion. For now, just keep in mind that remote, branch, and remote-tracking branchare all different things in Git. They're all related in various ways, but it's important to remember that they are not the same, and the terms have very specific meanings. The word trackis also overloaded. The new term upstreamis better, but not all descriptions use it.)
(编辑:您可能很合理地想知道/
的上游设置中的来自哪里origin/master
。这部分是历史文物。不幸的是,它导致了大量的混乱。现在,请记住remote、branch和remote眼睛跟踪分支是Git中所有不同的东西。他们以各种方式所有相关的,但要记住,他们是不一样的是非常重要的,并且术语具有非常特定的含义。这个词的轨道也被超载。新学期上游更好,但并非所有描述都使用它。)
回答by Dave
No, remote
is a parent structure of origin
. That's just the default name of the remote
Git creates when you clone a repository.
不,remote
是origin
. 这只是remote
克隆存储库时 Git 创建的默认名称。
More information in this question: What is “origin” in Git?
这个问题的更多信息:什么是 Git 中的“起源”?