Your branch is based on 'origin/xxxx', but the upstream is gone

1. 问题描述

从远程拉下代码后,本地新建了一个分支 aBranch,并且执行:

git branch --set-upstream-to=origin/aBranch

之后又在此分支基础上新建了一个分支 bBranch,然后git push origin --delete origin/aBranch 删除了远程分支 aBranch, 本地 git status

Your branch is based on 'origin/aBranch', but the upstream is gone.
  (use "git branch --unset-upstream" to fixup)

git pull 报错:

Your configuration specifies to merge with the ref 'refs/heads/aBranch'
from the remote, but no such ref was fetched.

2. 解决

  1. 下面返回的是本地分支连接的远程名称为origin 一般来说默认远程都是这个名字
git config --get branch.bBranch.remote
>origin
  1. 下面说明本地的这条 bBranch 分支是和远程的 aBranch 分支关联的(注意:即使远程的 aBranch 分支已经被删除了,这里还是会保留 aBranch 的关联,所以这才是这个问题的关键所在)
git config --get branch.bBranch.merge
> refs/heads/aBranch

联系这两条内容,可以知道远程名为origin,并且本地分支 bBranch 所关联的远程分支为 aBranch.
git branch -a 查看本地和远程所有分支。

解决:
–set-upstream-to 命令来更改本地分支关联的远程分支,这个命令会把branch.bBranch.remotebranch.bBranch.merge 都更改

git branch --set-upstream-to=origin/bBranch

参考文章:
解决git中upstream丢失问题Your branch is based on 'origin/xxxx', but the upstream is gone.

你可能感兴趣的:(Your branch is based on 'origin/xxxx', but the upstream is gone)