Menu
Coddy logo textTech

Git: Delete a Remote Branch

Last updated

Deleting a branch locally doesn't remove it from the remote - that's a separate step. To delete a branch on the remote (like GitHub), run git push origin --delete <branch>. Afterwards, other clones may still show the branch until they prune stale remote-tracking references.

Try these in the terminal playground - a real shell in your browser, nothing to install.

git push origin --delete removes the branch on the remote; your local branches are untouched.

Syntax

CommandWhat it does
git push origin --delete featureDelete feature on the remote
git push origin :featureOlder colon syntax, same effect
git branch -d featureDelete the branch locally too
git fetch --pruneRemove stale remote-tracking branches

Full cleanup

Remove the branch everywhere and tidy stale refs.

StepCommandResult
1git push origin --delete featureGone from the remote
2git branch -d featureGone locally
3git fetch --pruneClears origin/feature tracking ref

Git delete remote branch FAQ

How do I delete a remote branch in Git?
Run git push origin --delete <branch>. This removes the branch from the remote (for example GitHub). The older equivalent is git push origin :<branch>. Deleting the remote branch does not delete your local copy - do that separately with git branch -d <branch>.
Does deleting a local branch delete the remote one?
No. git branch -d only removes the branch from your local repository. The branch stays on the remote until you explicitly delete it with git push origin --delete <branch>. The two are independent.
Why does the deleted branch still show up?
Other clones keep remote-tracking references (like origin/feature) until they prune them. Run git fetch --prune (or git remote prune origin) to remove references to branches that no longer exist on the remote.
What's the difference between --delete and the colon syntax?
They do the same thing. git push origin --delete <branch> is the clearer modern form; git push origin :<branch> is the older syntax (pushing "nothing" to the remote branch, which deletes it). Use --delete for readability.
Can I practice this online?
Yes. Open the terminal playground to run these commands in a real shell in your browser - nothing to install. Coddy's free interactive Git course also covers working with remotes step by step.
Coddy programming languages illustration

Learn Git with Coddy

GET STARTED