什么是git上游 [英] What is a git upstream

查看:147
本文介绍了什么是git上游的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建github-repo并将github-repo添加为远程

When you have created a github-repo and added the the github-repo as remote

git remote add origin https://github.com/githubname/reponame.git

然后您需要使用

git push -u origin master

我阅读了(为什么需要一直做`--set-upstream`?)这是一个简短的形式

I read (Why do I need to do `--set-upstream` all the time?) that this a short form for doing

git branch --set-upstream-to my_branch origin/my_branch
git push

确切地说什么是上游,为什么我需要设置它?网上对此信息很少.我知道有一个类似的主题'git remote add up'是什么? ,但是在我看来,它并不能完全解释上游是什么,git push -u origin master是什么,尤其是origin master指向的是本地存储库还是远程存储库?

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 push -u origin master

-u标志意味着您的本地分支将成为跟踪分支.也就是说,一个跟踪远程分支的分支(上游"分支),以便将来的git pull将知道要合并的分支,而git push将被定向到正确的远程分支.

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.

origin是您要推送到的远程存储库.

origin is the remote repository you are pushing to.

master是refspec参数. refspec参数指定将哪个本地分支推送到哪个远程分支.它可能很复杂,但是在这种情况下,缩写形式master表示将本地master分支推送到同名origin/master的远程分支.

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分支的以下信息添加到您的.git/config:

Technically, the tracking adds the following information about the master branch to your .git/config:

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

,它在.git/refs/remotes/origin/master处创建一个文件,代表远程分支.

and it creates a file here .git/refs/remotes/origin/master, representing the remote branch.

这篇关于什么是git上游的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆