繁体   English   中英

如何告诉Git总是拉主分支?

[英]How to tell Git to always pull the master branch?

我发现git docs在这个问题上非常神秘。 我想做一件简单的事情,但似乎这样做并不简单。

我有以下情况:

$ git remote -v
origin  git://192.168.0.49/mnt/repos
stick   /mnt/titanium/podaci/repos

我可以使用git pull从原点获取和合并,这样可以正常工作:

$ git pull
Already up-to-date.

我可以像这样从棍子里拉出来:

$ git pull stick master
Already up-to-date.

但是,当我从没有主要部分的棍子拉出来时,我得到这样的信息:

$ git pull stick
From /mnt/titanium/podaci/repos
 * [new branch]      su2009  -> stick/su2009
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me either.  Please
name which branch you want to merge on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details on the refspec.

If you often merge with the same branch, you may want to
configure the following variables in your configuration
file:

    branch.master.remote = <nickname>
    branch.master.merge = <remote-ref>
    remote.<nickname>.url = <url>
    remote.<nickname>.fetch = <refspec>

See git-config(1) for details.

有些事让我困惑。 您的配置文件 ”在这里意味着什么? 我应该编辑哪个文件,以及我应该输入什么? 这个案子的昵称是什么?

我希望我想要完成的事情非常普遍,但我无法通过一个例子找到一个直截了当的答案。

“您的配置文件”在这里意味着什么?

您的repo的配置文件,位于您的repo根目录下的.git/config ~/.gitconfig上还有一个每用户全局配置文件,但你不想在那里放置特定于repo的设置。)

我应该编辑哪个文件,以及我应该输入什么?

您可以使用git config程序来编写配置信息,而不是手动输入。 但是,如果你想手动完成,只需打开.git/config - 语法相当简单。

这个案子的昵称是什么?

在这种情况下,昵称是遥控器的名称 - 所以“棒”。 您不必担心remote.*选项,因为已经设置了这些选项,但您确实需要设置branch.*选项。 这些选项告诉Git在使用stick进行git pull时要合并什么。

假设从棒上做git pull时你想从棒中合并大师。 你可以这样做:

# Sets stick as default remote for git pull.
# Note that origin will no longer be the default remote for git pull!
$ git config branch.master.remote stick

# Automatically merge in stick's master branch when doing a git pull
$ git config branch.master.merge refs/heads/master

所以现在,当你在没有任何远程或refspec信息的情况下执行git pull ,它将从stick获取所有分支,并在stick的master分支中合并。 请注意,原点不再是默认的遥控器; 要合并origin的master分支,你必须使用git pull origin master

如果你不想更改默认的遥控器,你将不得不继续使用git pull stick master

暂无
暂无

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

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