使用"manage remotes"选项,我已将新的IP保存为"origin_remote",并尝试将我的代码推送到那里,但由于某种原因,我收到了这个警告(或信息)。我不确定自己是否做错了什么。既然只是更改了IP地址并基本上向同一个repo推送,操作不应该顺畅吗?为什么Git告诉我这是一个新分支呢?
其他答案已经解释了为什么会出现这种情况,并且说明这不是Git,而是GitExtensions的警告。
因此,我建议尝试一些方法来消除这个消息。 我在两个使用Git Extensions 2.48.05和git版本1.9.5.msysgit.0的虚拟存储库上进行了测试,运行在Windows 7上。(此时Stack Overflow不允许我添加截图。)
./git/config
文件(以防万一)[branch "..."]
和[remote "..."]
部分,并保存该文件。Repository -> Remote repositories...
Name
中输入您喜欢的名称,例如origin_remote
Url
中输入您要推送/拉取的URLSave changes
New remote
对话框将弹出
您是否要自动配置此远程的默认推送和拉取行为?
按下Yes
。这应该自动添加远程分支引用并执行运行git remote update
。关闭对话框并刷新Git扩展,以查看存储库图形(浏览)视图中远程引用的状态。它们应该看起来像本地分支,但颜色是绿色的,名称格式为origin_remote/your_branch_name
现在当您使用Push
对话框时,在Remote
字段中选择origin_remote
。您不应再看到任何警告。
./git/config
文件中应该得到类似以下内容:[remote "origin_remote"]
url = URL_TO_YOUR_REPOSITORY
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "your_branch_name"]
remote = origin_remote
merge = refs/heads/your_branch_name
[branch "your_other_branch_name"]
remote = origin_remote
merge = refs/heads/your_other_branch_name
虽然VonC已经正确回答了问题,但还有一些额外的细节:
Git Extensions仅检查本地config
文件,从而做出错误且相当棘手的假设。
一个本地仓库可以有多个远程仓库,但每个分支在config
文件中只能有一个branch
部分,将该分支映射到特定的远程仓库(无论如何将分支映射到多个远程仓库都没有意义,因为branch
部分仅用于简化push
和pull
命令,允许您省略remote
和branch
参数)。
在我们这样的场景中,一个仓库指定了多个远程仓库,但是branch
部分只映射到其中一个,每次尝试推送到这些次要远程仓库时,就会出现此警告。如果您习惯了它,那么没关系,但对于第一次看到它的人来说,它立即给人一种错误即将发生并应该避免的感觉。
/refs
中。Git扩展仅检查本地config
文件,因此该消息提供了错误信息。push
还可以删除远程存储库中的分支一样。在这种情况下,由于Git扩展仅检查本地config
文件,您可能根本不会收到警告,尽管它比添加一个分支更危险。这似乎只是Git Extension警告(即仅使用Git不会给您相同的警告)。
//Extra check if the branch is already known to the remote, give a warning when not.
//This is not possible when the remote is an URL, but this is ok since most users push to
//known remotes anyway.
if (TabControlTagBranch.SelectedTab == BranchTab && PushToRemote.Checked)
{
//If the current branch is not the default push, and not known by the remote
//(as far as we know since we are disconnected....)
if (RemoteBranch.Text != GetDefaultPushRemote(_NO_TRANSLATE_Remotes.Text) &&
!Module.GetHeads(true, true).Any(x => x.Remote == _NO_TRANSLATE_Remotes.Text && x.LocalName == RemoteBranch.Text) )
//Ask if this is really what the user wants
if (!Settings.DontConfirmPushNewBranch)
if (MessageBox.Show(owner, _branchNewForRemote.Text, _pushCaption.Text, MessageBoxButtons.YesNo) ==
DialogResult.No)
{
return false;
}
}
这取决于 git 扩展 是否记录了上游分支:
使用命令行 git 命令进行检查:
git config branch.master
查看一下 branch.master.remote 是否仍然指向旧的 IP 地址而不是别名 'origin',同时 git remote -v 显示新的 IP 地址下的 origin。
如果是这样的话,请重新使用远程名称记录上游分支:
git config branch.master.remote origin