你如何让git总是从特定的分支中拉出来? [英] How do you get git to always pull from a specific branch?

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

问题描述

我不是一个混帐大师,但我已经使用它一段时间了,有几个不同的项目。在每个项目中,我总是 git clone [repository] ​​,并且从这一点开始,总是可以 git pull ,只要当然,我没有任何突出的变化。



最近,我不得不恢复到以前的分支,并使用 git checkout 4f82a29 。当我再次准备好拉时,我发现我必须将我的分支重新设置为主。现在,我无法使用直接的 git pull ,但是必须指定 git pull origin master ,这是令人讨厌,并向我表明我并不完全理解正在发生的事情。



什么改变了哪些不允许我直接做 git pull 没有指定源主,以及如何将其更改回来?



更新:

  -bash-3.1 $ cat config 
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[branchmaster]
[remoteorigin]
url = git@github.com:user / project.git
fetch = refs / heads / *:refs / remotes / origin / *

更新2:我的原始方法可能不正确,但我需要修复此回购,以便我可以简单地再次使用 git pull 。目前,git pull的结果是:

  -bash-3.1 $ git pull 
你问我没有告诉我拉你
想要合并的分支,
中的'branch.master.merge',你的配置文件也不会告诉我。请
命名你想要在命令行中合并的分支,
再次尝试(例如'git pull')。
有关refspec的详细信息,请参阅git-pull(1)。

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

branch.master。 remote =
branch.master.merge =
remote..url =
remote..fetch =

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

我可以告诉 git pull 合并,并且它能正常工作,但是 git pull 不能像我在 git checkout 之前那样工作。 [branchmaster] 下,尝试将以下内容添加到repo的Git配置文件( .git / config ):

  [branch master] 
remote = origin
merge = refs / heads / master

这告诉Git 2的东西:


  1. 当你在master分支上时,默认的远程是原点。 $ b
  2. 在master分支上使用 git pull 时,如果未指定远程和分支,请使用默认远程(原始)并合并远程主机分支。

我不确定为什么这个设置会从您的配置中删除。您可能需要遵循其他人发布的建议,但这可能会起作用(或至少有帮助)。



如果您不想编辑你可以使用命令行工具:

  $ git config branch.master.remote origin 
$ git config branch.master.merge refs / heads / master


I'm not a git master, but I have been working with it for some time now, with several different projects. In each project, I always git clone [repository] and from that point, can always git pull, so long as I don't have outstanding changes, of course.

Recently, I had to revert to a previous branch, and did so with git checkout 4f82a29. When I was again ready to pull, I found that I had to set my branch back to master. Now, I can not pull using a straight git pull but instead, have to specify git pull origin master, which is annoying, and indicates to me that I don't fully understand what is going on.

What has changed which does not allow me to do a straight git pull without specifying origin master, and how to I change it back?

UPDATE:

-bash-3.1$ cat config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[branch "master"]
[remote "origin"]
    url = git@github.com:user/project.git
    fetch = refs/heads/*:refs/remotes/origin/*

UPDATE 2: To be clear, I understand that my original method may have been incorrect, but I need to fix this repo so that I can simply use git pull again. Currently, git pull results in:

-bash-3.1$ git pull
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  ').
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 = 
    branch.master.merge = 
    remote..url = 
    remote..fetch = 

See git-config(1) for details.

I can tell git pull which branch to merge, and it works correctly, but git pull does not work as it did originally before my git checkout.

解决方案

Under [branch "master"], try adding the following to the repo's Git config file (.git/config):

[branch "master"]
    remote = origin
    merge = refs/heads/master

This tells Git 2 things:

  1. When you're on the master branch, the default remote is origin.
  2. When using git pull on the master branch, with no remote and branch specified, use the default remote (origin) and merge in the changes from the remote master branch.

I'm not sure why this setup would've been removed from your configuration, though. You may have to follow the suggestions that other people have posted, too, but this may work (or help at least).

If you don't want to edit the config file by hand, you can use the command-line tool instead:

$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master

这篇关于你如何让git总是从特定的分支中拉出来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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