- Forget remote branches that no longer exist
git fetch --pruneRun this inside your project. It removes entries like origin/fix-login when that branch was deleted on GitHub. Your own local branches stay untouched.
- Find local branches whose remote is gone
git branch -vvLook for lines that end with ": gone]". Those branches were deleted on GitHub, usually after a pull request was merged.
- Move off the branch you want to delete
git switch mainGit won't delete the branch you are on. Use your main branch name if it is different.
- Delete the old local branch
git branch -d fix-loginGit refuses if the branch has work that isn't merged. If the pull request was squash merged, Git may still refuse. Use git branch -D {{branch}} only when you are sure the work is safe on GitHub.
- Prune on every fetch from now on (optional)
git config --global fetch.prune trueAfter this, every git fetch and git pull cleans up deleted remote branches for you.
Check it worked
- Check no branch shows as gone
git branch -vv - List the remote branches Git still knows about
git branch -r
Undo it
- Find the last commit of a deleted branch
git reflogLook for the commit you were on in that branch and copy its short ID.
- Bring the branch back
git branch fix-login <commit-id>Replace <commit-id> with the ID from git reflog.
- Stop pruning on every fetch
git config --global --unset fetch.prune
- Forget remote branches that no longer exist
git fetch --pruneRun this inside your project. It removes entries like origin/fix-login when that branch was deleted on GitHub. Your own local branches stay untouched.
- Find local branches whose remote is gone
git branch -vvLook for lines that end with ": gone]". Those branches were deleted on GitHub, usually after a pull request was merged.
- Move off the branch you want to delete
git switch mainGit won't delete the branch you are on. Use your main branch name if it is different.
- Delete the old local branch
git branch -d fix-loginGit refuses if the branch has work that isn't merged. If the pull request was squash merged, Git may still refuse. Use git branch -D {{branch}} only when you are sure the work is safe on GitHub.
- Prune on every fetch from now on (optional)
git config --global fetch.prune trueAfter this, every git fetch and git pull cleans up deleted remote branches for you.
Check it worked
- Check no branch shows as gone
git branch -vv - List the remote branches Git still knows about
git branch -r
Undo it
- Find the last commit of a deleted branch
git reflogLook for the commit you were on in that branch and copy its short ID.
- Bring the branch back
git branch fix-login <commit-id>Replace <commit-id> with the ID from git reflog.
- Stop pruning on every fetch
git config --global --unset fetch.prune
- Forget remote branches that no longer exist
git fetch --pruneRun this inside your project in PowerShell or Git Bash. It removes entries like origin/fix-login when that branch was deleted on GitHub. Your own local branches stay untouched.
- Find local branches whose remote is gone
git branch -vvLook for lines that end with ": gone]". Those branches were deleted on GitHub, usually after a pull request was merged.
- Move off the branch you want to delete
git switch mainGit won't delete the branch you are on. Use your main branch name if it is different.
- Delete the old local branch
git branch -d fix-loginGit refuses if the branch has work that isn't merged. If the pull request was squash merged, Git may still refuse. Use git branch -D {{branch}} only when you are sure the work is safe on GitHub.
- Prune on every fetch from now on (optional)
git config --global fetch.prune trueAfter this, every git fetch and git pull cleans up deleted remote branches for you.
Check it worked
- Check no branch shows as gone
git branch -vv - List the remote branches Git still knows about
git branch -r
Undo it
- Find the last commit of a deleted branch
git reflogLook for the commit you were on in that branch and copy its short ID.
- Bring the branch back
git branch fix-login <commit-id>Replace <commit-id> with the ID from git reflog.
- Stop pruning on every fetch
git config --global --unset fetch.prune