Git 远程分支已删除,但本地还有

情景

仓库中,如果在删除了一些无用的分支后,我们本地,还会缓存有相应的分支信息,使用 git branch -a 可以看到或者使用 git pull 时,出现以下提示:

Your configuration specifies to merge with the ref 'hotfix/illegal_get_user_new'
from the remote, but no such ref was fetched.

这都是由于本地分支信息与远程仓库不同步导致,解决方法如下:

git pull --prune origin或者 git pull -p或者 git fetch -p

其实 -p 与 --prune 是同一个参数

一个更详细的命令查看分支的追踪情况:

git remote show origin

结果如下:

 remote origin
Fetch URL: git@192.168.1.38:kelvin/morseapp-api.git # 仓库地址
Push URL: git@192.168.1.38:kelvin/morseapp-api.git # Push 地址
HEAD branch: master # ???
Remote branches: # 远程拥有的分支
dev tracked
master tracked
test tracked
# 下面是本地分支,在使用 git pull 时,会从哪个远程分支获取数据
Local branches configured for 'git pull':
bi merges with remote bi
dev merges with remote dev
# 以下是本地分支Push时,会合并到哪个远程分支的配置
Local refs configured for 'git push':
bi pushes to bi (up to date)
dev pushes to dev (up to date)