“git pull”和“git pull origin master”有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52108832/
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
What is the difference between 'git pull' and 'git pull origin master'?
提问by kgbph
What is the difference between git pull
and git pull origin master
?
git pull
和 和有什么不一样git pull origin master
?
What if I am on a branch other than master
, will the two commands achieve a different result?
如果我在 以外的分支上master
,这两个命令会获得不同的结果怎么办?
回答by Nagaraj
Remember, a pull is a fetch and a merge.
请记住,拉取是提取和合并。
git pull origin masterfetches commits from the master branch of the origin remote (into the local origin/master branch), and then it merges origin/master into the branch you currently have checked out.
git pullonly works if the branch you have checked out is tracking an upstream branch. For example, if the branch you have checked out tracks origin/master,
git pull
is equivalent togit pull origin master
git pull origin master从远程 origin 的 master 分支获取提交(到本地 origin/master 分支),然后将 origin/master 合并到您当前检出的分支中。
git pull仅在您签出的分支正在跟踪上游分支时才有效。例如,如果您检出的分支跟踪 origin/master,
git pull
则相当于git pull origin master
回答by Sana Jahan
First, let us understand what git pull
is:
首先,让我们了解什么git pull
是:
The git pullcommand is used to fetch and download content from a remote repository and immediately update the local repository to match that content. The
git pull
command is a combination ofgit fetch
andgit merge
.git pull
will download the content from the remote repository. Once the content is downloaded,git merge
will merge the content to your local repository. A new merge commit will be created and HEAD updated to point at the new commit.Now that we know what
git pull
does, when we dogit pull origin master
, it simply fetches a copy of themaster
branch from the original repository, and merges it with the current branch that you have checked out.
该混帐拉命令用于获取和从远程仓库下载内容,并立即更新本地存储库的内容相匹配。该
git pull
命令是一个组合git fetch
和git merge
。git pull
将从远程存储库下载内容。下载内容后,git merge
会将内容合并到您的本地存储库。将创建一个新的合并提交并更新 HEAD 以指向新的提交。现在我们知道做什么了
git pull
,当我们这样做时git pull origin master
,它只是master
从原始存储库中获取分支的副本,并将其与您签出的当前分支合并。
For more information, you can go to this link.
有关更多信息,您可以转到此链接。
回答by paulsm4
From the documentation:
从文档:
https://git-scm.com/docs/git-pull
git pull [<options>] [<repository> [<refspec>…?]]
git-pull - Fetch from and integrate with another repository or a local branch
...
Default values for and are read from the "remote" and "merge" configuration for the current branch as set by git-branch[1] --track.
https://git-scm.com/docs/git-pull
git pull [<options>] [<repository> [<refspec>…?]]
git-pull - 从另一个存储库或本地分支获取并集成
...
和的默认值是从 git-branch[1] --track 设置的当前分支的“远程”和“合并”配置中读取的。
So
所以
If your branch is set to "master", then git pull and git pull origin master will do the same thing.
If your branch is set to "master", Git pull and git pull origin some-other-branch will be different
If your branch is set to "some-other-branch", then Git pull and git pull origin master will be different
如果你的分支设置为“master”,那么 git pull 和 git pull origin master 会做同样的事情。
如果您的分支设置为“master”,则 Git pull 和 git pull origin some-other-branch 会有所不同
如果你的分支设置为“some-other-branch”,那么 Git pull 和 git pull origin master 就会不同
回答by Chukwuemeka Inya
Git pull = Git fetch + Git merge.
Git pull = Git fetch + Git 合并。
git pull origin masterLet's say you are on local/master, and run this command, git will fetch commits from origin/master and then merge it into local/master.
git pull origin master假设您在 local/master 上,并运行此命令,git 将从 origin/master 获取提交,然后将其合并到 local/master。
git pullThis is a shorthand for pulling commits into local branch that is tracking a remote branch.
git pull这是将提交拉入跟踪远程分支的本地分支的简写。
And that brings the question, how does one make a local branch track a remote branch.
这就带来了一个问题,如何让本地分支跟踪远程分支。
As far as I know, there are two common ways to do so:
1. When pushing for the first time:
git push -u origin branch_name
The -u
flag tells git to make the local branch track the remote branch.
据我所知,常见的有两种方法可以这样做:
1,当按下首次:
git push -u origin branch_name
该-u
标志告诉混帐使当地分行追踪远程分支。
- When creating a local branch for an existing remote branch:
git branch --track branch_name origin/branch_name
- 为现有远程分支创建本地分支时:
git branch --track branch_name origin/branch_name