2016-07-22 53 views
1

我创造了我的本地机器上的一个新的实验分支:如何正确的远程分支名VS本地分支名不匹配

git checkout -b feature/random-experiments 

然后做了一些修改几个文件,并承诺他们:

git add . 
git commit -m "1st cut - added cool new experimental feature" 
git push 

后来,我们创建了一个用户故事(U-123),然后决定重命名我的分支以遵循我们的命名标准。我通过存储的浏览器UI删除了远程分支。然后:

git branch -m feature/U123-Add-Cool-New-Feature 

然后做了一些修改,并承诺:

git add . 
git commit -m "clean up & refactor" 

但现在,当我做了git的状态

$ git status 
On branch feature/U123-Add-Cool-New-Feature 
Your branch and 'origin/feature/random-experiments' have diverged, 
and have 1 and 1 different commit each, respectively. 
    (use "git pull" to merge the remote branch into yours) 
Changes not staged for commit: 
    (use "git add <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 

它看起来像我的本地分支仍然指向旧的远程分支。这是一个问题,因为旧的(远程)分支在原点: 1)有一个不同的名称 2)不再存在,因为我删除它。

解决此问题的最佳方法是什么?

回答

0

您可以reset the upstream branch for your current branch

git branch branch_name --set-upstream-to your_new_remote/branch_name 

你的情况:

git branch --unset-upstream 
git push --set-upstream-to origin feature/U123-Add-Cool-New-Feature 

确保你在正确的地方分支:

git checkout feature/U123-Add-Cool-New-Feature 

并尝试从那里推。

+0

当我尝试这个时,我收到一条错误消息,指出原点/特征/ U123-Add-Cool-New-Feature不存在。我最终完成了2个步骤:1)git branch --unset-upstream,然后2)git push --set-upstream-to origin特性/ U123-Add-Cool-New-Feature。 (注意原点和功能之间的空格。 – SGB

+0

@SGB好的,我已经编辑了相应的答案。 – VonC

相关问题