为什么我需要始终执行`--set-upstream`? [英] Why do I need to do `--set-upstream` all the time?

查看:143
本文介绍了为什么我需要始终执行`--set-upstream`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Git中创建了一个新的分支:

  git分支my_branch 

按下它:

  git push origin my_branch 

现在说某人在服务器上做了一些更改,我想从 origin / my_branch 。我这样做:

  git pull 

但是我得到:

 你问我拉不告诉我你$ b $哪个分支b想和
中的'branch.my_branch.merge'合并,你的配置文件也不会告诉我。请
指定你想在命令行使用哪个分支,
再试一次(例如'git pull< repository>< refspec>')。
有关详细信息,请参阅git-pull(1)。

如果您经常与同一分支合并,您可能希望
在您的配置文件中使用以下内容:

[branchmy_branch]
remote =<昵称>
merge =< remote-ref>

[远程<昵称>]
url =< url>
fetch =< refspec>

有关详细信息,请参阅git-config(1)。

我了解到,我可以使用它:

  git branch --set-upstream my_branch origin / my_branch 



但为什么我需要为我创建的每个分支做这件事?是不是很明显,如果我将 my_branch 放入 origin / my_branch ,那么我想拉 origin / my_branch my_branch

解决方案

一个快捷方式,不依赖于记住<$ c的语法$ c> git branch --set-upstream 1 就是:

  git push -u origin my_branch 

...您第一次推送该分支。你只需要做一次,就可以像 git branch一样,在你的分支和 origin 之间建立关联。 set-upstream 确实如此。



个人而言,我认为在分支和远程分支之间建立关联是一件好事明确。这只是一个耻辱,规则是不同于 git push git pull




1 这可能听起来很愚蠢,但我经常忘记指定当前分支,假设这是默认的 - 不是的,结果是最令人困惑的:)



更新2012-10-11 :显然我并不是唯一一个发现很容易出错的人!感谢 VonC 指出git 1.8.0引入了更为明显的 git分支--set -upstream-to ,如果您位于分支 my_branch

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


$

  git分支-u原点/ my_branch 

这个变化及其推理在 git 1.8.0发布说明,候选版本1


很容易说 git branch --set-upstream origin / master ,但是它告诉Git安排本地分支 origin / master 与当前签出的分支集成,这非常不可能是用户的意思。该选项已弃用;改为使用新的 - set-upstream-to (带有简短的 -u )选项。



I create a new branch in Git:

git branch my_branch

Push it:

git push origin my_branch

Now say someone made some changes on the server and I want to pull from origin/my_branch. I do:

git pull

But I get:

You asked me to pull without telling me which branch you
want to merge with, and 'branch.my_branch.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:

    [branch "my_branch"]
    remote = <nickname>
    merge = <remote-ref>

    [remote "<nickname>"]
    url = <url>
    fetch = <refspec>

See git-config(1) for details.

I learned that I can make it work with:

git branch --set-upstream my_branch origin/my_branch

But why do I need to do this for every branch I create? Isn't it obvious that if I push my_branch into origin/my_branch, then I would want to pull origin/my_branch into my_branch? How can I make this the default behavior?

解决方案

A shortcut, which doesn't depend on remembering the syntax for git branch --set-upstream 1 is to do:

git push -u origin my_branch

... the first time that you push that branch. You only need to do it once, and that sets up the association between your branch and the one at origin in the same way as git branch --set-upstream does.

Personally, I think it's a good thing to have to set up that association between your branch and one on the remote explicitly. It's just a shame that the rules are different for git push and git pull.


1 It may sound silly, but I very frequently forget to specify the current branch, assuming that's the default - it's not, and the results are most confusing :)

Update 2012-10-11: Apparently I'm not the only person who found it easy to get wrong! Thanks to VonC for pointing out that git 1.8.0 introduces the more obvious git branch --set-upstream-to, which can be used as follows, if you're on the branch my_branch:

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

... or with the short option:

git branch -u origin/my_branch

This change, and its reasoning, is described in the release notes for git 1.8.0, release candidate 1:

It was tempting to say git branch --set-upstream origin/master, but that tells Git to arrange the local branch origin/master to integrate with the currently checked out branch, which is highly unlikely what the user meant. The option is deprecated; use the new --set-upstream-to (with a short-and-sweet -u) option instead.

这篇关于为什么我需要始终执行`--set-upstream`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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