Git Delete Remote Branch Example |Video upload date:  · Duration: PT4M55S  · Language: EN

Learn safe commands to remove a remote Git branch and confirm removal on origin with simple steps for GitHub GitLab and other remotes

If you have ever created a branch, pushed it to origin, and then forgotten about it until it became a fossil, welcome to the club. This guide shows how to remove a remote Git branch without drama and how to confirm origin no longer remembers your bad decisions. Commands are the same whether you use GitHub or another Git hosting service.

Refresh remote state

Before you hit the nuclear button, get an accurate view of what the remote thinks exists. That avoids deleting the wrong branch and starting a support ticket with your future self.

git fetch --prune

This fetch will update remote refs and prune any branches that were deleted on the server. It keeps your local view in sync with origin so you do not chase ghosts.

Delete the local branch when it is safe

Only delete your local branch after merging or confirming the work is no longer needed. Use the safe delete first and use force only when you know what you are doing.

git branch -d feature/name

If Git refuses because the branch is unmerged and you are sure you want to destroy it, use this:

git branch -D feature/name

Remember that -d will protect you from losing commits. -D will not. Choose wisely unless you enjoy rewriting history as a hobby.

Delete the branch from the remote

Deleting a remote branch is mostly a single push command wrapped in a little ceremony. This tells origin to drop the named branch.

git push origin --delete feature/name

That is the modern explicit form. Older tutorials may show pushing an empty ref but do not follow those into the internet dark ages.

Verify remote branch removal

Always confirm origin no longer lists the branch. A quick check prevents surprise reappearances during sprint demos.

  • List remote branches from your local repo with
git branch -r
  • Or query the server directly with
git ls-remote --heads origin

If neither command shows the branch name then congrats. The branch is gone from origin and you can go drink something celebratory or pretend you meant to do this all along.

Quick checklist before you delete

  • Make sure changes are merged or saved elsewhere
  • Run git fetch --prune so you have an accurate remote view
  • Prefer git branch -d locally and only use -D if necessary
  • Use git push origin --delete to remove the branch on the server
  • Verify with git branch -r or git ls-remote --heads origin

Tips for less painful branch hygiene

  • Use descriptive branch names so forgotten branches are less mysterious
  • Open a pull request before deleting so audits and CI logs still make sense
  • Consider pruning stale branches periodically as part of your devops routine

Deleting a remote branch is simple when you follow these steps. Fetch first, delete local only when safe, push the delete, and then verify. Your repository will thank you or at least stop cluttering the branch list.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.