You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何本地删除Git分支?解决删除远程跟踪分支时的‘分支未找到’报错

Fixing "branch 'remotes/origin/incident' not found" When Deleting Git Branches

Hey there! Let's break down why you're hitting that error and how to fix it quickly.

Why the Error Happens

The git branch -d command is built to delete local branches—but remotes/origin/incident isn't a regular local branch. It's a local "tracking reference" that mirrors the remote branch stored on your origin server. That's why Git can't locate it when you run that command directly.

Solutions Based on What You Need

Pick the option that aligns with your goal:

1. Delete the actual remote branch (on the origin server)

If you want to remove the branch from the remote repository entirely, run this command:

git push origin --delete incident

This sends a request to the origin server to delete the incident branch. After running this, your local references will sync up with the remote automatically, or you can run git fetch to force an update.

2. Delete only the local tracking reference (keep the remote branch intact)

If the remote branch still exists but you just want to remove its local mirror (so it no longer shows up in git branch -a), use one of these methods:

  • Delete the specific reference:
    git branch -d -r origin/incident
    
    The -r flag tells Git you're targeting remote branch references instead of local branches.
  • Clean all outdated remote references:
    If you have multiple remote branches that no longer exist on the server, prune all of them at once:
    git fetch origin --prune
    # OR
    git remote prune origin
    
    Both commands will remove any local tracking references for branches that have already been deleted from the origin server.

Verify the Fix

After running the command that fits your needs, check the full list of branches (local and remote) to confirm the reference is gone:

git branch -a

内容的提问来源于stack exchange,提问作者Ali Asgher Badshah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:58:26