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
Difference between git pull and git pull origin master
提问by Sachin Kainth
What is the difference between these two commands?
这两个命令有什么区别?
git pull
and
和
git pull origin master
采纳答案by torek
[Edit, May 2018: git pull
is 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 pull
script is meant as a convenience method for invoking git fetch
followed by git merge
(or, with git pull --rebase
, invoking git fetch
followed by git rebase
).
该git pull
脚本旨在作为调用git fetch
后跟git merge
(或使用git pull --rebase
,调用git fetch
后跟git rebase
)的便捷方法。
The first extra argument to git pull
tells it which remote to give to the fetch
operation:
第一个额外的参数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 pull
tell 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 feature2
that tracks origin/feature
:
第二个(和任何其他)参数git pull
告诉它要合并到哪个或多个分支。这些是在遥控器上找到的分支的名称。例如,假设您创建了一个feature2
跟踪origin/feature
以下内容的新分支:
$ git checkout -b feature2 origin/feature
If you now want to fetch from origin
to pick up new commits added to their feature
branch, but merge them in to your local feature2
branch:
如果您现在想从 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 remotebr1br2
will run git fetch
followed by a series of separate git merge
-s on each branch, but that's not what happens.
请注意,如果您列出多个分支名称,Git 将进行“章鱼合并”。根据我的经验,这通常会让人们第一次感到惊讶:他们认为将在每个分支上运行后跟一系列单独的-s,但事实并非如此。git pull remotebr1br2
git fetch
git merge
回答by nitesh goel
git pull origin master
will pull changes from the origin remote, master branch and merge them to the local checked-out branch.
git pull origin master
将从源远程主分支拉取更改并将它们合并到本地检出分支。
where as git pull
will fetch new commits from all tracked branches from the default remote(origin). you can also configure default remote and branch name in gitconfig
file.
asgit pull
将从默认远程(原点)的所有跟踪分支中获取新提交。您还可以在gitconfig
文件中配置默认远程和分支名称。
git branch --set-upstream master origin/master
This will add the following info to your gitconfig
file:
这会将以下信息添加到您的gitconfig
文件中:
[branch "master"]
remote = origin
merge = refs/heads/master
now whenever you say git pull
it will fetch from origin master.
现在每当你说它git pull
会从原始主人那里获取。
回答by poke
git pull origin master
is 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 pull
without giving any parameter. Traditionally, this has been equivalent to sayinggit pull origin
. However, when configurationbranch.<name>.remote
is 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>.fetch
are consulted, and if there aren't any,$GIT_DIR/remotes/<origin>
file is consulted and itsPull:
lines are used.
经常有人在
git pull
不给任何参数的情况下使用。传统上,这相当于说git pull origin
。但是,当branch.<name>.remote
在 branch 上存在配置时<name>
,将使用该值而不是原点。[…]
为了确定在命令行上没有任何 refspec 参数的情况下运行命令时要获取哪些远程分支(并可选择存储在远程跟踪分支中),会查询配置变量的值
remote.<origin>.fetch
,如果没有,$GIT_DIR/remotes/<origin>
查阅文件并使用其Pull:
行。