本地分支配置成了追踪远端的 master,但远端并没有 master,因为把远端master改为了 main。修一下追踪分支就能 git pull 了。

D:\code\ideaprojects\face-recognition> git pull         
Your configuration specifies to merge with the ref 'refs/heads/master'
from the remote, but no such ref was fetched.
D:\code\ideaprojects\face-recognition>

快速修复(当前就在 main 开发的话)

# 1) 拉取最新远端分支信息
git fetch --all --prune

# 2) 切到 main(若不存在就基于远端创建)
git switch main 
# git switch -c main origin/main

# 3) 绑定上游为 origin/main(以后直接 git pull 即可)
git branch --set-upstream-to=origin/main main

# 4) 拉取
git pull

如果你现在在 master 分支上工作(远端没有 master)

把本地 master 改名为 main 并对齐远端:

git fetch --all --prune
git branch -m master main
git branch --set-upstream-to=origin/main main
git pull

检查与诊断

git remote show origin          # 看远端默认分支、各分支状态
git branch -vv                  # 看本地分支追踪关系
git ls-remote --heads origin    # 列出远端实际存在的分支

小贴士

  • 如果之前有未提交改动阻碍切换分支,先 git add ... && git commit -m "...",或 git stash push -u -m "wip" 再切换。
  • 想让远端的默认分支(HEAD)自动识别:git remote set-head origin -a(仅影响显示,不会自动改你的本地追踪设置)。
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐