简体   繁体   English

git 上游并跟踪远程分支

[英]git upstream and tracking a remote branch

I am a bit wondering about the naming "upstream" from git.我有点想知道 git 的命名“上游”。

If I create a local branch如果我创建一个本地分支

git checkout -b branch_local

and want to push it somewhere想把它推到某个地方

git push remote_id branch_local:branch_remote

If I look which remote the branch follows:如果我查看分支遵循哪个远程:

git branch -vv --all

I see that there is nothing set.我看到没有任何设置。 If I try:如果我尝试:

git pull

I get我明白了

If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=<remote>/<branch> branch_local

Why I have to set the "upstream" to get the "downstream" set?为什么我必须设置“上游”才能获得“下游”集? Maybe I have not understood if there is an additional downstream setting?可能我没明白有没有额外的下游设置?

"Upstream" refers to the remote the branch will push and pull by default. “上游”是指分支默认情况下将推动和拉动的遥控器。 This is also called the "remote tracking branch". 这也称为“远程跟踪分支”。 Sometimes Git will set this for you when you create the branch, but it depends on how you're configured. 有时,当您创建分支时,Git会为您设置此设置,但这取决于您的配置方式。

In order to ensure the upstream branch is set, use git push -u the first time you push. 为了确保设置了上游分支,请在首次git push -u使用git push -u

git push -u remote branch_local:branch_remote

You can change branch.autoSetupMerge to make Git do this automatically. 您可以更改branch.autoSetupMerge以使Git自动执行此操作。 true will set up tracking when you branch from a remote branch like git co -b foo remote/foo . 当您 git co -b foo remote/foo的远程分支分支时, true会设置跟踪。 always will always do the tracking. always将始终进行跟踪。

You need to tell git to have your local branch track the remote branch. 您需要告诉git让您的本地分支跟踪远程分支。 Git being a distributed system, you can make plenty of local branches that don't track any upstream changes. Git是一个分布式系统,您可以创建大量不跟踪任何上游更改的本地分支机构。

What you've done is push your local branch to the remote repository, but the local is still not tracking the upstream. 您要做的是将本地分支推送到远程存储库,但是本地分支仍未跟踪上游。 There's no "downstream" per se, upstream is the git terminology for the remote repository you're tracking. 本身没有“下游”,上游是您要跟踪的远程存储库的git术语。 Once you set that, both push and pull should work (assuming fetch and push urls are the same, but I'm guessing they are at this stage) 设置好之后,push和pull都应该起作用(假设fetch和push url是相同的,但我想它们处于现阶段)

Why I have to set the "upstream"为什么我必须设置“上游”

As of git 2.37+, you no longer need to if you set a new configuration parameter:从 git 2.37+ 开始,如果您设置新的配置参数,则不再需要

git config --global push.autoSetupRemote true

With this set, a simple git push in your example above (with branch_local checked out) will push that to the remote ( origin/branch_local ), and set the tracking branch relationship.有了这个集合,一个简单的git push在你上面的例子中(签出branch_local )将把它推送到远程( origin/branch_local ),设置跟踪分支关系。


In previous versions of git or without this config, you need to do a more complex push like git push -u origin HEAD , where the -u sets the tracking relationship and the explicit origin and branch are required because the tracking relationship doesn't exist yet.在之前版本的 git 或没有此配置时,您需要执行更复杂的推送,如git push -u origin HEAD ,其中-u设置跟踪关系,并且需要显式来源和分支,因为跟踪关系不存在然而。

(assuming that the push.default config is at its default setting of simple ) (假设push.default配置的默认设置为simple

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM