[英]“git remote -v” shows (fetch) and (push) twice, once for 'github' and once for 'origin' what does that mean?
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. 我学会了命令
git remote -v
来检查远程状态。 Well, all the git tutorial had snapshots like this , showing the result: 好了,所有的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
. 但是,当我尝试使用该命令时,对于
origin
和github
都得到了相似的结果。 Something like this: 像这样:
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. 我不确定这个
github
和origin
在这里意味着什么。 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.
将我指向其他一些解释此问题的教程也可以。
Feel free to suggest edits. 随时提出修改建议。
Git supports multiple remotes, so this is a normal enough state. Git支持多个遥控器,因此这是一个足够正常的状态。 Edit : as sschuberth answered , it's not quite normal to have the same URL for multiple remotes.
编辑 :作为sschuberth回答 ,这不是很正常到有多个遥控器相同的URL。 It's not harmful but you might as well delete one of them.
这不是有害的,但您最好删除其中之一。
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. Git将每个这样的名称存储在配置文件中。 Under that name, Git can then store additional information, such as one or more URLs.
然后,使用该名称,Git可以存储其他信息,例如一个或多个URL。 (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. (要使一个遥控器有用,它需要至少有一个URL作为其
url
设置存储。)要进行抓取,Git通常还需要为每个遥控器至少设置一个fetch
设置。
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
. 最常见的是,您的每个Git存储库都只有一个远程(通常称为
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. 这是因为当
git clone
通过复制某些现有存储库创建新存储库时,它会在新存储库中记录现有存储库的URL。 To record this, it creates a remote, and by default, it uses the name origin
for that remote. 要记录此消息,它将创建一个远程,默认情况下,它将使用该远程的名称
origin
。
The git remote add
sub-command adds additional remotes. git remote add
子命令添加其他遥控器。 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. 您为遥控器指定一个名称和一个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
将列出您已设置的两个(或更多)远程。
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. 当您运行
git fetch
或git push
,下一个单词通常是要从中获取或推送到的远程服务器的名称。 For instance, git fetch origin
fetches from the remote named origin
. 例如,
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
. 如果您有两个遥控器,一个名为fred,一个名为srujan,则可以
git fetch fred
或git fetch srujan
。 Similarly, you can git push fred
or git push srujan
. 同样,您可以
git push fred
或git push srujan
。 These will contact the specified remote, using the URL stored under that remote. 它们将使用存储在该遥控器下的URL与指定的遥控器联系。
When fetching from a remote, your Git will copy their Git's branches, but rename them so that they are unique to that particular remote. 从远程获取时 ,您的Git将复制其Git的分支,但重命名它们,以便它们对于特定的远程是唯一的。 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-tracking branches named srujan/master
and srujan/develop
. 例如,如果我从远程
srujan
获取,并且srujan的Git(位于指定的URL)具有master
和develop
分支,那么我将获得名为srujan/master
和srujan/develop
远程跟踪分支。 If I then fetch from remote fred
, I will get remote-tracking branches like fred/master
and fred/develop
. 如果然后从远程
fred
获取,我将获得诸如fred/master
和fred/develop
类的远程跟踪分支。
git pull
? git pull
呢? The git pull
command is meant to be a convenient shorthand for git fetch
followed by git merge
. git pull
命令是git fetch
和git merge
的便捷快捷方式。 Like git fetch
, git pull
takes a third word, which is the name of the remote. 像
git fetch
一样, git pull
需要第三个单词,这是遥控器的名称。 The main thing git pull
does with this is hand it off to git fetch
. git pull
的主要作用是将其交给git fetch
。
The weird thing about git pull
is that it also takes branch names. 关于
git pull
的怪异之处在于它还带有分支名称。 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 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 either the fetch step to fail (if your network connection goes down, for instance) or the merge step to fail (if the merge cannot be done automatically). 你平时最好只运行
git fetch
自己,至少在第一,因为它可能要么取步骤就是失败的(如果您的网络连接出现故障,例如) 或合并步骤就是失败的(如果合并不能自动完成)。 Until you are very familiar with Git, I believe you are better off knowing precisely which step has gone wrong, because you will need to take different actions to fix it, depending on which step failed. 在您不熟悉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 can get
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 not complicated 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尝试一次完成所有操作之前,请不要使用
git pull
。)
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. 在Git中,“远程”基本上只是服务器URL的别名,因此您不必一直输入完整的URL。 If you don't explicitly specify a remote name, the default name is
origin
. 如果您未明确指定远程名称,则默认名称为
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). 在您的情况下,您有两个远程服务器,
origin
和github
,指向相同的URL(无论出于何种原因;您可能都遵循了一些教程步骤来创建github
远程服务器以进行演示)。 So one of the two is superfluous. 因此,两者之一是多余的。 As
github
is the non-standards name, I'd simply remote that remote again by typing 由于
github
是非标准名称,因此我只需键入以下内容即可再次远程
git remote rm github
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.