简体   繁体   English

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

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

I find git docs very cryptic regarding this issue. 我发现git docs在这个问题上非常神秘。 I want to do a simple thing, but it seems doing it is not simple at all. 我想做一件简单的事情,但似乎这样做并不简单。

I have the following situation: 我有以下情况:

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

I can use git pull to fetch and merge from origin, and that works fine: 我可以使用git pull从原点获取和合并,这样可以正常工作:

$ git pull
Already up-to-date.

I can pull from stick like this: 我可以像这样从棍子里拉出来:

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

However, when I pull from stick without the master part, I get this message: 但是,当我从没有主要部分的棍子拉出来时,我得到这样的信息:

$ 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.

Some things confuse me here. 有些事让我困惑。 What does " your configuration file " mean here? 您的配置文件 ”在这里意味着什么? Which file should I edit, and what exactly should I type in? 我应该编辑哪个文件,以及我应该输入什么? What's nickname in this case? 这个案子的昵称是什么?

I would expect that what I'm trying to accomplish is very common, but I haven't been able to find a straight-to-the-point answer with an example. 我希望我想要完成的事情非常普遍,但我无法通过一个例子找到一个直截了当的答案。

What does "your configuration file" mean here? “您的配置文件”在这里意味着什么?

Your repo's configuration file, found at .git/config at the root of your repo. 您的repo的配置文件,位于您的repo根目录下的.git/config (There's also a per-user global config file at ~/.gitconfig , but you don't want to put repo-specific settings there.) ~/.gitconfig上还有一个每用户全局配置文件,但你不想在那里放置特定于repo的设置。)

Which file should I edit, and what exactly should I type in? 我应该编辑哪个文件,以及我应该输入什么?

You can use the git config program to write configuration information, instead of entering it manually. 您可以使用git config程序来编写配置信息,而不是手动输入。 However, if you want to do it manually, just open up .git/config -- the syntax is fairly straightforward. 但是,如果你想手动完成,只需打开.git/config - 语法相当简单。

What's nickname in this case? 这个案子的昵称是什么?

Nickname, in this case, is the name of the remote -- so "stick". 在这种情况下,昵称是遥控器的名称 - 所以“棒”。 You don't have to worry about the remote.* options, as those have already been set up, but you do need to set the branch.* options. 您不必担心remote.*选项,因为已经设置了这些选项,但您确实需要设置branch.*选项。 These options tell Git what to merge when doing a git pull from stick. 这些选项告诉Git在使用stick进行git pull时要合并什么。

Say you want to merge in master from stick when doing a git pull from stick. 假设从棒上做git pull时你想从棒中合并大师。 You can do so like this: 你可以这样做:

# 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

So now, when you do a git pull without any remote or refspec info, it'll fetch all the branches from stick, and merge in stick's master branch. 所以现在,当你在没有任何远程或refspec信息的情况下执行git pull ,它将从stick获取所有分支,并在stick的master分支中合并。 Note that origin will not be the default remote anymore; 请注意,原点不再是默认的遥控器; to merge in origin's master branch, you'll have to use git pull origin master . 要合并origin的master分支,你必须使用git pull origin master

If you don't want to change the default remote to stick, you'll have to continue using git pull stick master . 如果你不想更改默认的遥控器,你将不得不继续使用git pull stick master

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

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