如何告诉Git总是拉主分支? [英] How to tell Git to always pull the master branch?

查看:112
本文介绍了如何告诉Git总是拉主分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现git文档对这个问题非常神秘。我想做一件简单的事情,但它似乎并不简单。

I find git docs very cryptic regarding this issue. 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

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

I can use git pull to fetch and merge from origin, and that works fine:

$ git pull
Already up-to-date.

我可以像 stick 这样拉

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

但是,当我从主页 / strong>部分,我收到以下消息:

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?

您的仓库配置文件位于 .git / config 在你的回购的根源。 (还有一个每用户全局配置文件〜/ .gitconfig ,但你不想在这里放置特定于repo的设置。)

Your repo's configuration file, found at .git/config at the root of your repo. (There's also a per-user global config file at ~/.gitconfig, but you don't want to put repo-specific settings there.)


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

Which file should I edit, and what exactly should I type in?

您可以使用 git config 程序编写配置信息,而不是手动输入。但是,如果您想手动执行此操作,只需打开 .git / config - 语法非常简单。

You can use the git config program to write configuration information, instead of entering it manually. However, if you want to do it manually, just open up .git/config -- the syntax is fairly straightforward.


这种情况下的昵称是什么?

What's nickname in this case?

昵称在这种情况下是远程 - 所以坚持。您不必担心远程。* 选项,因为这些选项已经设置完毕,但您需要设置分支。 * 选项。这些选项告诉Git在执行 git pull 时从棒中合并的内容。

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. These options tell Git what to merge when doing a git pull from stick.

假设您想要在master从stick执行 git pull 时出现。你可以这样做:

Say you want to merge in master from stick when doing a git pull from stick. 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

现在,当您执行 git pull 没有任何远程或refspec信息,它会从棒中获取所有分支,并在棒的主分支中合并。请注意,原点不再是默认的遥控器;要在原始主分支中合并,你必须使用 git pull origin 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. 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.

如果你不' t想要将默认的遥控器改为stick,您必须继续使用 git pull stick master

If you don't want to change the default remote to stick, you'll have to continue using git pull stick master.

这篇关于如何告诉Git总是拉主分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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