bash “git remote -v”显示 (fetch) 和 (push) 两次,一次用于“github”,一次用于“origin”,这是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37741924/
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
"git remote -v" shows (fetch) and (push) twice, once for 'github' and once for 'origin' what does that mean?
提问by Srujan Barai
Not sure if its the right place for asking this question, I was unable to understand something and googling didn't help.
不确定它是否是问这个问题的正确地方,我无法理解某些东西,谷歌搜索也没有帮助。
I have been referring git
tutorials, (obviously meaning i'm new to it).
我一直在参考git
教程,(显然意味着我是新手)。
I learnt the command git remote -v
to check the remote status. Well, all the git tutorial had snapshots like this, showing the result:
我学会了git remote -v
检查远程状态的命令。好了,所有的git的教程民政事务快照像这样,显示结果:
origin https://github.com/something/something-else.git (fetch)
origin https://github.com/something/something-else.git (push)
But when I tried the command I am getting similar result for origin
as well as github
. Something like this:
但是,当我试图命令我得到类似的结果为origin
,以及github
。像这样的东西:
github https://github.com/srujan7/something-something-url.git (fetch)
github https://github.com/srujan7/something-something-url.git (push)
origin https://github.com/srujan7/something-something-url.git (fetch)
origin https://github.com/srujan7/something-something-url.git (push)
Problem:
问题:
I am not sure what does this github
and origin
here means. Why did I get it twice? (unlike the tutorial)I am also not sure if did anything wrong, or its perfectly right. Pointing me to some other tutorial explaining this will also do.
我不确定 thisgithub
和origin
here 是什么意思。为什么我收到了两次?(与教程不同)我也不确定是否做错了什么,或者完全正确。将我指向其他一些解释这一点的教程也可以。
Feel free to suggest edits.
随时提出修改建议。
采纳答案by torek
Git supports multiple remotes, so this is a normal enough state. Edit: as sschuberth answered, it's notquite normal to have the same URL for multiple remotes. It's not harmfulbut you might as well delete one of them.
Git 支持多个遥控器,所以这是一个足够正常的状态。 编辑:正如sschuberth 回答的那样,多个遥控器具有相同的 URL 不太正常。这无害,但您不妨删除其中之一。
What is a remote?
什么是遥控器?
A remote is just a name, like origin
or upstream
or github
or even fred
or srujan
.
远程仅仅是一个名称,如origin
或upstream
或github
或甚至fred
或srujan
。
Git stores each such name in a configuration file. Under that name, Git can then store additional information, such as one or more URLs. (For a remote to be useful it needs to have at least one URL, stored as its url
setting.) For fetching, Git normally needs at least one fetch
setting per remote as well.
Git 将每个这样的名称存储在一个配置文件中。然后,在该名称下,Git 可以存储其他信息,例如一个或多个 URL。(要使遥控器有用,它需要至少有一个 URL,作为其url
设置存储。)对于获取,Git 通常fetch
每个遥控器也至少需要一个设置。
When git remote -v
lists two or more remotes
当git remote -v
列出两个或更多遥控器时
Most commonly, each of your Git repositories will have just one remote, usually named origin
. This is because when git clone
creates a new repository by copying some existing repository, it records (in the new repository) the URL of the existing repository. To record this, it creates a remote, and by default, it uses the name origin
for that remote.
最常见的是,您的每个 Git 存储库都只有一个远程,通常命名为origin
. 这是因为当git clone
通过复制一些现有存储库来创建新存储库时,它会记录(在新存储库中)现有存储库的 URL。为了记录这一点,它创建了一个遥控器,默认情况下,它使用该origin
遥控器的名称。
The git remote add
sub-command adds additional remotes. You specify a name for the remote and a URL, and Git records the new remote name and sets its main URL to the one you just gave.
该git remote add
子命令添加了额外的遥控器。您指定远程名称和 URL,Git 会记录新的远程名称并将其主 URL 设置为您刚刚提供的名称。
After this, git remote
or git remote show
will list the two (or more) remotes you have set up.
在此之后,git remote
或git remote show
将列出您设置的两个(或更多)遥控器。
How do I use a remote?
如何使用遥控器?
When you run git fetch
or git push
, the very next word is normally the name of the remote to fetch from or push to. For instance, git fetch origin
fetches from the remote named origin
.
当您运行git fetch
或 时git push
,下一个词通常是要从中获取或推送到的远程名称。例如,git fetch origin
从名为 的远程获取origin
。
If you have two remotes, one named fred and one named srujan, you can git fetch fred
or git fetch srujan
. Similarly, you can git push fred
or git push srujan
. These will contact the specified remote, using the URL stored under that remote.
如果您有两个遥控器,一个名为 fred,一个名为 srujan,您可以git fetch fred
或git fetch srujan
。同样,您可以git push fred
或git push srujan
。这些将使用存储在该遥控器下的 URL 联系指定的遥控器。
When fetchingfrom a remote, your Git will copy their Git's branches, but renamethem so that they are unique to that particular remote. For instance, if I fetch from remote srujan
, and srujan's Git (at the specified URL) has branches master
and develop
, I will get remote-trackingbranches named srujan/master
and srujan/develop
. If I then fetch from remote fred
, I will get remote-tracking branches like fred/master
and fred/develop
.
当从远程获取时,您的 Git 将复制其 Git 的分支,但重命名它们以便它们对于该特定远程是唯一的。例如,如果我从 remote 获取srujan
,并且 srujan 的 Git(在指定的 URL 处)有分支master
and develop
,我将得到名为and 的远程跟踪分支。如果我然后从 remote 获取,我将获得远程跟踪分支,如和。srujan/master
srujan/develop
fred
fred/master
fred/develop
What about git pull
?
怎么样git pull
?
The git pull
command is meant to be a convenient shorthand for git fetch
followed by git merge
. Like git fetch
, git pull
takes a third word, which is the name of the remote. The main thing git pull
does with this is hand it off to git fetch
.
该git pull
命令旨在成为git fetch
后跟的便捷简写git merge
。像git fetch
,git pull
需要第三个词,即遥控器的名称。git pull
与此有关的主要事情是将其交给git fetch
.
The weird thing about git pull
is that it also takes branch names. It uses those in an odd way: git pull srujan master
means "run git fetch srujan
first, then run git merge surjan/master
".
奇怪的git pull
是它也需要分支名称。它以一种奇怪的方式使用这些:git pull srujan master
意思是“git fetch srujan
先运行,然后运行git merge surjan/master
”。
You're usually better off just running git fetch
yourself, at least at first, because it's possible for eitherthe fetch step to fail (if your network connection goes down, for instance) orthe merge step to fail (if the merge cannot be done automatically). Until you are very familiar with Git, I believe you are better off knowing precisely whichstep has gone wrong, because you will need to take different actions to fix it, depending on which step failed.
通常你最好只是运行git fetch
自己,至少在第一,因为它可能要么取指步骤就是失败的(如果您的网络连接出现故障,例如)或合并步骤就是失败的(如果合并不能被自动完成)。在您非常熟悉 Git 之前,我相信您最好准确地知道哪一步出错了,因为您将需要采取不同的措施来修复它,这取决于哪一步失败了。
You may also want to rebase rather than merging. This is, if anything, more complex than merging (although often a better approach too). You canget git pull
to do a rebase instead of a merge, and in fact you can make this happen automatically, but the details are a little bit complicated, and manually running git fetch
first, and then git rebase
second, is notcomplicated at all.
您可能还想变基而不是合并。如果有的话,这比合并更复杂(尽管通常也是更好的方法)。你可以得到git pull
做底垫,而不是合并,实际上可以让这个自动发生,但细节有点复杂,并手动运行git fetch
,然后再git rebase
第二,是不是在所有复杂。
(In short, don't use git pull
until you are very familiar with fetching, merging, and rebasing, and are ready to allow Git to try to do them all at once.)
(简而言之,在git pull
您非常熟悉获取、合并和变基,并准备好让 Git 尝试一次性完成所有这些操作之前,请不要使用。)
回答by sschuberth
In Git, a "remote" basically just is an alias for a server URL, so you don't have to type the full URL all the time. If you don't explicitly specify a remote name, the default name is origin
. In your case, you have two remotes, origin
and github
, pointing to the same URL (for whatever reason; you probably followed some tutorial steps to create the github
remote for demonstration purposes). So one of the two is superfluous. As github
is the non-standards name, I'd simply remote that remote again by typing
在 Git 中,“远程”基本上只是服务器 URL 的别名,因此您不必一直输入完整的 URL。如果您没有明确指定远程名称,则默认名称为origin
. 在您的情况下,您有两个遥控器,origin
和github
,指向相同的 URL(无论出于何种原因;您可能按照一些教程步骤来创建github
遥控器以进行演示)。所以两者之一是多余的。正如github
非标准名称一样,我只需通过键入再次远程远程
git remote rm github