如何本地删除Git分支?解决删除远程跟踪分支时的‘分支未找到’报错
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:
Thegit branch -d -r origin/incident-rflag 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:
Both commands will remove any local tracking references for branches that have already been deleted from thegit fetch origin --prune # OR git remote prune originoriginserver.
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

