如何使git始终从特定分支中提取?

我不是git master,但是我已经和它一起工作了一段时间了,并且有几个不同的项目。当然,在每个项目中,从那时git clone [repository]起,我始终可以git pull,并且只要没有特别的变化,我就可以始终如此。


最近,我不得不还原到上一个分支,并使用进行了此操作git checkout 4f82a29。当我再次准备拉动时,我发现必须将分支设置回master。现在,我不能使用直线git pull,而是必须指定git pull origin master,这很烦人,并向我表明我不完全了解发生了什么。


发生了什么变化,哪些使我无法在git pull不指定原点大师的情况下进行平直比赛?如何更改它?


更新:


-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/*

更新2:明确地说,我知道我的原始方法可能不正确,但是我需要修复此存储库,以便可以git pull再次使用。目前,git pull导致:


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

我可以说出git pull要合并的分支,它可以正常工作,但git pull不能像原来的分支那样工作git checkout。


一只斗牛犬
浏览 539回答 3
3回答

慕哥6287543

在下[branch "master"],尝试将以下内容添加到仓库的Git配置文件(.git/config):[branch "master"]    remote = origin    merge = refs/heads/master这告诉Git 2件事:当您在master分支上时,默认的遥控器是origin。在git pullmaster分支上使用(未指定任何远程和分支)时,请使用默认的remote(来源)并合并来自remote master分支的更改。我不确定为什么会从您的配置中删除此设置。您可能也必须遵循其他人发布的建议,但这可能有用(或至少有帮助)。如果您不想手动编辑配置文件,则可以使用命令行工具:$ git config branch.master.remote origin$ git config branch.master.merge refs/heads/master
打开App,查看更多内容
随时随地看视频慕课网APP