Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何更正远程分支名称与本地分支名称不匹配_Git - Fatal编程技术网

Git 如何更正远程分支名称与本地分支名称不匹配

Git 如何更正远程分支名称与本地分支名称不匹配,git,Git,我在本地机器上创建了一个新的实验分支: git checkout -b feature/random-experiments 然后对几个文件进行了一些更改并提交: git add . git commit -m "1st cut - added cool new experimental feature" git push 后来,我们创建了一个用户故事(U-123),然后决定按照我们的命名标准重命名我的分支。我通过stash的浏览器UI删除了远程分支。然后: git branch -m fe

我在本地机器上创建了一个新的实验分支:

git checkout -b feature/random-experiments
然后对几个文件进行了一些更改并提交:

git add .
git commit -m "1st cut - added cool new experimental feature"
git push
后来,我们创建了一个用户故事(U-123),然后决定按照我们的命名标准重命名我的分支。我通过stash的浏览器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)
$git状态
在分支功能上/U123添加新功能
你的分支和“起源/特征/随机实验”出现分歧,
和分别有1个和1个不同的提交。
(使用“git pull”将远程分支合并到您的分支中)
未为提交而暂存的更改:
(使用“git add…”更新将提交的内容)
(使用“git签出--…”放弃工作目录中的更改)
看起来我的本地分支仍然指向旧的远程分支。这是一个问题,因为原点处的旧(远程)分支: 1) 有一个不同的名字 2) 当我删除它时,它不再存在

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

您可以:

就你而言:

 git branch --unset-upstream 
 git push --set-upstream-to origin feature/U123-Add-Cool-New-Feature
确保您在正确的本地分支上:

git checkout feature/U123-Add-Cool-New-Feature
然后尝试从那里推动。

您可以:

就你而言:

 git branch --unset-upstream 
 git push --set-upstream-to origin feature/U123-Add-Cool-New-Feature
确保您在正确的本地分支上:

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

然后尝试从那里推动。

当我尝试此操作时,收到一条错误消息,指示origin/feature/U123 Add Cool New feature不存在。最后我完成了一个两步的过程:1)git分支——取消上游设置,然后2)git推送——将上游设置为原始功能/U123添加新功能。(请注意origin和feature之间的间距。当我尝试此操作时,我收到一条错误消息,指示origin/feature/U123 Add Cool New feature不存在。我最后执行了一个两步过程:1)git branch--取消上游设置,然后2)git push--将上游设置为origin feature/U123 Add Cool New feature。(请注意原点和特征之间的间距。