git pull 和 git pull origin master 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23953125/
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 18:08:50  来源:igfitidea点击:

Difference between git pull and git pull origin master

gitgithub

提问by Sachin Kainth

What is the difference between these two commands?

这两个命令有什么区别?

git pull

and

git pull origin master

采纳答案by torek

[Edit, May 2018: git pullis no longer a shell script and a few details are different in modern Git. Pull also now has recursion options that make it more useful with submodules. This answer ignores the submodules.]

[编辑,2018 年 5 月:git pull不再是 shell 脚本,现代 Git 中的一些细节有所不同。Pull 现在还具有递归选项,使其对子模块更有用。这个答案忽略了子模块。]

The git pullscript is meant as a convenience method for invoking git fetchfollowed by git merge(or, with git pull --rebase, invoking git fetchfollowed by git rebase).

git pull脚本旨在作为调用git fetch后跟git merge(或使用git pull --rebase,调用git fetch后跟git rebase)的便捷方法。

The first extra argument to git pulltells it which remote to give to the fetchoperation:

第一个额外的参数git pull告诉它给fetch操作提供哪个遥控器:

git pull origin

for example, means to fetch from origin. If you leave this out, Git uses the current branch's remote:

例如,表示从 中获取origin。如果您忽略这一点,Git 将使用当前分支的remote

$ git branch
* master
$ git config --get branch.master.remote
origin

The second (and any additional) arguments to git pulltell it which branch or branches to merge in. These are the names of the branches as found on the remote. For instance, suppose you create a new branch feature2that tracks origin/feature:

第二个(和任何其他)参数git pull告诉它要合并到哪个或多个分支。这些是在遥控器上找到的分支的名称。例如,假设您创建了一个feature2跟踪origin/feature以下内容的新分支:

$ git checkout -b feature2 origin/feature

If you now want to fetch from originto pick up new commits added to their featurebranch, but merge them in to your local feature2branch:

如果您现在想从 fetch from 获取origin添加到其feature分支的新提交,但将它们合并到您的本地feature2分支:

$ git pull origin feature

If you leave out the branch name(s), git uses the current branch's merge:

如果省略分支名称,git 将使用当前分支的merge:

$ git config --get branch.feature2.merge
feature

Note that if you list multiple branch names, Git will do an "octopus merge". In my experience, this usually surprises people the first time: they think git pull remotebr1br2will run git fetchfollowed by a series of separate git merge-s on each branch, but that's not what happens.

请注意,如果您列出多个分支名称,Git 将进行“章鱼合并”。根据我的经验,这通常会让人们第一次感到惊讶:他们认为将在每个分支上运行后跟一系列单独的-s,但事实并非如此。git pull remotebr1br2git fetchgit merge

回答by nitesh goel

git pull origin masterwill pull changes from the origin remote, master branch and merge them to the local checked-out branch.

git pull origin master将从源远程主分支拉取更改并将它们合并到本地检出分支。

where as git pullwill fetch new commits from all tracked branches from the default remote(origin). you can also configure default remote and branch name in gitconfigfile.

asgit pull将从默认远程(原点)的所有跟踪分支中获取新提交。您还可以在gitconfig文件中配置默认远程和分支名称。

git branch --set-upstream master origin/master

This will add the following info to your gitconfigfile:

这会将以下信息添加到您的gitconfig文件中:

[branch "master"]
    remote = origin
    merge = refs/heads/master

now whenever you say git pullit will fetch from origin master.

现在每当你说它git pull会从原始主人那里获取。

回答by poke

git pull origin masteris the verbose form which specifies both the remote (origin) and the branch to pull from (master). If you don't specify that, Git will apply a default behavior that is explained in the documentation:

git pull origin master是详细形式,它指定远程 ( origin) 和要从中提取的分支 ( master)。如果您没有指定,Git 将应用文档中解释的默认行为:

Often people use git pullwithout giving any parameter. Traditionally, this has been equivalent to saying git pull origin. However, when configuration branch.<name>.remoteis present while on branch <name>, that value is used instead of origin.

[…]

In order to determine what remote branches to fetch (and optionally store in the remote-tracking branches) when the command is run without any refspec parameters on the command line, values of the configuration variable remote.<origin>.fetchare consulted, and if there aren't any, $GIT_DIR/remotes/<origin>file is consulted and its Pull:lines are used.

经常有人在git pull不给任何参数的情况下使用。传统上,这相当于说git pull origin。但是,当branch.<name>.remote在 branch 上存在配置时<name>,将使用该值而不是原点。

[…]

为了确定在命令行上没有任何 refspec 参数的情况下运行命令时要获取哪些远程分支(并可选择存储在远程跟踪分支中),会查询配置变量的值remote.<origin>.fetch,如果没有,$GIT_DIR/remotes/<origin>查阅文件并使用其Pull:行。