git 创建新分支并关联远程分支_Git新建本地分支与远程分支关联问题:git branch --set-upstream(示例代码)...

本文详细介绍了在Git中新建本地分支并将其与远程分支进行关联的方法。解决了在未设置远程分支映射时,执行git pull等命令出现的问题。通过具体实例展示了如何使用git branch --set-upstream命令来完成分支的关联。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Git新建本地分支与远程分支关联问题:git branch --set-upstream

git在本地新建分支, push到remote服务器上之后,再次pull下来的时候,如果不做处理会报以下提示:

You asked me to pull without telling me which branch you

want to merge with, and ‘branch.production.merge‘inyour configuration file does not tell me, either. Please

specify which branch you want to use on the command line and

try again (e.g. ‘git pull ‘).

See git-pull(1) fordetails.Ifyou often merge with the same branch, you may want to

use something like the followinginyour configuration file:

[branch"debug"]

remote= merge= [remote""]

url= fetch= See git-config(1) for details.

问题解析:

git本地新建一个分支后,必须要做远程分支关联。如果没有关联, git 会在下面的操作中提示你显示的添加关联。关联目的是如果在本地分支下操作: git pull, git push ,不需要指定在命令行指定远程的分支. 推送到远程分支后, 你只要没有显示指定, git pull 的时候,就会提示你。

解决方法:

使用命令git branch --set-upstream ;实例如下,其中debug为创建的分支

git branch --set-upstream debug origin/debug

命令的最终修改都是针对 config 文件。

使用-- set-upstream 去跟踪远程分支。

[core]

repositoryformatversion= 0filemode= truebare= truelogallrefupdates= true[remote"origin"]

fetch= +refs/heads/*:refs/remotes/origin/*url= [email protected]:android2.3.5_r1.git

[branch"master"]

remote=origin

merge= refs/heads/master

[branch"debug"]

remote=origin

merge= refs/heads/debug

[receive]

denyCurrentBranch= ignore

注意仓库.git目录下的config文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值