简体   繁体   English

为新分支设置上游

[英]Setting upstream for new branch

Alright ! 好的 ! I have created a branch prac . 我创建了一个分支prac I am doing my changes, committing them and merging them with master. 我正在做我的更改,将它们提交并与master合并。

In short this is what I do usually for my workflow consisting of two branches namely - Master and prac. 简而言之,这是我通常对包含两个分支(Master和Prac)的工作流执行的操作。 Whenever, I want to do something, I code in prac branch 每当我想做某事时,我都会在prac分支中进行编码

  1. git checkout prac git checkout实践

  2. git add whatever, git commit -m "so n so" git添加任何东西,git commit -m“ so n so”

  3. git checkout master git checkout主

  4. git merge prac git merge prac

I do not delete my branch usually to be in a frame of mind that I always have one branch for practice and master for showcase of final code.Comments are welcome to improve my mindset :D 我通常不会出于自己的想法而删除我的分支机构,因为我总是有一个分支机构可以作为练习,而大师级则可以展示最终代码。欢迎发表评论以改善我的心态:D

Now, I deliberately hit git push . 现在,我故意打git push I noticed the following 我注意到以下

fatal: The current branch prac has no upstream branch. 致命的:当前分支实践没有上游分支。 To push the current branch and set the remote as upstream, use 要推送当前分支并将远程设置为上游,请使用

git push --set-upstream origin prac

Now, my questions is that if I set upstream for this prac branch to remote, then will I need to do merge ? 现在,我的问题是,如果我将此Prac分支的上游设置为remote,那么是否需要合并? Or how basically it's different from merging? 或与合并有什么根本不同?

From what I understand, after setting upstream, I already have pushed the changes to main repo. 据我了解,设置上游之后,我已经将更改推送到了主仓库中。 So what will be left to merge ? 那么剩下什么要合并? Or does this pushes to some new instance/fork which has to be pushed later ? 还是将其推送到某些新实例/分支,然后再将其推送?

Confusion my friends confusion!!! 困惑我的朋友们困惑!!!

The upstream setting is a relationship between your local branch and a branch on the remote repo. upstream设置是您的本地分支与远程存储库上的分支之间的关系。 It has nothing to do with merging one local branch into another (except possibly if you contrive a perverse combination of config settings); 它与将一个本地分支合并到另一个本地分支无关(除非您可能是配置设置的错误组合); it affects how refs are updated when doing a push (in situations where no configuration or command argument specifies a different behavior), and (as torek points out in comments) can also serve as a default ref for merging. 它会影响执行push时引用的更新方式(在没有配置或命令参数指定其他行为的情况下),并且(如torek在注释中指出的那样)还可以用作合并的默认引用。

So now git push will, by default, update the prac branch on origin if you're on the prac branch locally. 因此,如果您位于本地的prac分支上,那么默认情况下,现在git push将默认在origin上更新prac分支。 But this doesn't incorporate your prac changes into master on either repo - which is what merge does. 但是,这并不包括你的prac变成master在任回购-这正是merge呢。

It struck me seeing a dropdown on another repo that it has branches listed. 令我感到震惊的是,它看到了另一个列出分支机构的仓库的下拉列表。 So I pushed my branch by setting upstream and it did what I thought. 因此,我通过设置上游来推动分支机构,它实现了我的想法。 It simply added a new branch to my repo along with master. 它只是与master一起在我的仓库中添加了一个新分支。

So I guess this answers my query 所以我想这回答了我的查询

From what I understand, after setting upstream, I already have pushed the changes to main repo. 据我了解,设置上游之后,我已经将更改推送到了主仓库中。 So what will be left to merge ? 那么剩下什么要合并? Or does this pushes to some new instance/fork which has to be pushed later ? 还是将其推送到某些新实例/分支,然后再将其推送?

Also from this I am clear about the merge thing as well. 从这个我也很清楚合并的事情。 It's comparing apples and oranges. 它正在比较苹果和桔子。

However, useful article pointed by torek about merge and detailed insight. 但是,torek指出了有关合并和详细见解的有用文章。 Now after doing this Mark's answer makes a bit more sense. 现在,在完成此操作后,Mark的答案就更有意义了。 Therefore accepting that 因此接受

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

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