简体   繁体   English

“ git remote -v”显示(获取)和(推送)两次,一次用于“ github”,一次用于“ origin”是什么意思?

[英]“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 . 但是,当我尝试使用该命令时,对于origingithub都得到了相似的结果。 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. 我不确定这个githuborigin在这里意味着什么。 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. 这不是有害的,但您最好删除其中之一。

What is a remote? 什么是遥控器?

A remote is just a name, like origin or upstream or github or even fred or srujan . 遥控器只是一个名称,例如originupstreamgithub甚至fredsrujan

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设置。

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 . 最常见的是,您的每个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 remotegit 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. 当您运行git fetchgit 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 fredgit fetch srujan Similarly, you can git push fred or git push srujan . 同样,您可以git push fredgit 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)具有masterdevelop分支,那么我将获得名为srujan/mastersrujan/develop 远程跟踪分支。 If I then fetch from remote fred , I will get remote-tracking branches like fred/master and fred/develop . 如果然后从远程fred获取,我将获得诸如fred/masterfred/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 . git pull命令是git fetchgit 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). 在您的情况下,您有两个远程服务器, origingithub ,指向相同的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.

相关问题 git push origin HEAD 是什么意思? - What does git push origin HEAD mean? “为‘git push’配置的本地引用:”列在‘git remote show origin’的输出中是什么意思? - What does the "Local refs configured for 'git push':" column mean in the output of `git remote show origin`? git remote -v输出标签(获取)和(推送),用于原始和上游查询 - git remote -v output tags (fetch) and (push) for origin and upstream query 没有源时,“ git push”会推送到哪个远程? - What remote does “git push” push to when there is no origin? `git fetch origin master:master`是什么意思? - What does `git fetch origin master:master` mean? git在Egit中一次推送到多个远程存储库 - git push to multiple remote repositories at once in Egit 删除多个git远程标签,推送一次 - Delete multiple git remote tags and push once 对于Git和Github,fork,master,origin,push,pull这两个术语是什么意思? - What do the terms fork, master, origin, push, pull mean for Git and Github? `git fetch origin`和`git remote update origin'有什么区别? - What is the difference between `git fetch origin` and `git remote update origin`? 为什么“在 Github 上共享项目”(来自 IntelliJ)有效,但“git push remote origin master”(来自终端)却不行? - Why “Share Project on Github” (from IntelliJ) works, but “git push remote origin master” (from Terminal) does not?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM