什么是上游 git
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17122245/
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 a git upstream
提问by patriques
When you have created a github-repo and added the the github-repo as remote
当您创建了 github-repo 并将 github-repo 添加为远程时
git remote add origin https://github.com/githubname/reponame.git
then you need to push your first commit with
那么你需要推送你的第一次提交
git push -u origin master
I read (Why do I need to do `--set-upstream` all the time?) that this a short form for doing
我读到(为什么我需要一直做`--set-upstream`?)这是一个简短的形式
git branch --set-upstream-to my_branch origin/my_branch
git push
What is a upstream exactly and why do I need to set it? There is little information about this on the net. I know that there is a similar topic What does 'git remote add upstream' help achieve?, but in my opinion it does not explain exactly what the upstream is and what git push -u origin master
does, especially what is origin master
pointing to, is it the local repo or the remote repo?
什么是上游,为什么我需要设置它?网络上关于这方面的信息很少。我知道有一个类似的主题“git remote add upstream”有助于实现什么?,但在我看来,它并没有准确解释上游是什么以及什么git push -u origin master
,特别是origin master
指向的是本地回购还是远程回购?
回答by Klas Mellbourn
In the command
在命令中
git push -u origin master
The -u
flag means that your local branch will become a tracking branch. That is, a branch that tracks a remote branch (the "upstream" branch), so that future git pull
will know which branch to merge from and git push
will be directed to the correct remote branch.
该-u
标志意味着您的本地分支将成为跟踪分支。也就是说,一个跟踪远程分支(“上游”分支)的分支,以便将来git pull
知道要从哪个分支合并git push
并将被定向到正确的远程分支。
origin
is the remote repository you are pushing to.
origin
是您要推送到的远程存储库。
master
is the refspec parameter. The refspec parameter specifies which local branch is pushed to what remote branch. It can be complicated, but in this case the short form master
means to push the local master
branch to the remote branch with the same name, origin/master
.
master
是 refspec 参数。refspec 参数指定将哪个本地分支推送到哪个远程分支。它可能很复杂,但在这种情况下,简短形式master
意味着将本地master
分支推送到具有相同名称的远程分支,origin/master
.
Technically, the tracking adds the following information about the master
branch to your .git/config
:
从技术上讲,跟踪会将有关master
分支的以下信息添加到您的.git/config
:
[branch "master"]
remote = origin
merge = refs/heads/master
and it creates a file here .git/refs/remotes/origin/master
, representing the remote branch.
并在此处创建一个文件.git/refs/remotes/origin/master
,代表远程分支。
回答by Ignacio Vazquez-Abrams
"Upstream" is the repo you cloned (some of) the branches in yours from, and where you push changes to those branches (and optionally entire new branches) once they've been committed. GitHub acts as your upstream because they store the revisions for you, in a centralized location.
“上游”是您从中克隆(部分)分支的存储库,以及在提交后将更改推送到这些分支(以及可选的整个新分支)的位置。GitHub 充当您的上游,因为它们在一个集中位置为您存储修订。