Git Delete Remote Branch ![rw-book-cover](https://salferrarello.com/wp-content/uploads/2022/11/avatar-salcode-400.jpeg) ## Metadata - Author: [[Sal Ferrarello]] - Full Title: Git Delete Remote Branch - Category: #articles - Document Note: To delete a remote branch named chore/fix-typo from the default remote named origin in Git, use the command "git push origin --delete chore/fix-typo." To simplify this process, users can create a Git alias by running the command "git config --global alias.drb '!git push origin --delete $(git rev-parse --abbrev-ref HEAD).'" This alias will delete the remote branch with the same name as the current local branch when the user types "git drb." The alias runs the same command as the original, but includes the current branch name. --- --- tags: - #git - #wordpress - #opensource Author: Sal Ferrarello Source: Website Reference: https://salferrarello.com/git-delete-remote-branch/ date created: 2025-08-21 00:00 --- # Title: Git delete remote branch — command and alias for deleting a remote Git branch ## Table of Contents: - [📝 Summary](#-summary) - [📖 Main Content](#-main-content) - [🗒️ Notes](#-notes) - [📖 References](#-references) - [🗣️ Paraphrase](#-paraphrase) - [📰 Newsletter](#-newsletter) - [✅ Action Items](#-action-items) - [🧪 Hypotheses](#-hypotheses) - [📊 Methodology](#-methodology) - [❓ Questions](#-questions) - [🔮 Future Research](#-future-research) - [💡 Implications](#-implications) - [🧠 Learning Styles Assessment](#-learning-styles-assessment) - [📊 Accessibility Assessment](#-accessibility-assessment) - [🌍 DEIB Assessment](#-deib-deib-assessment) - [✅ Logical validity](#-logical-validity) - [🔍 SEO Evaluation](#-seo-evaluation) - [🎯 Conclusion](#-conclusion) ### References: - Sal Ferrarello, “Git delete remote branch” - Git documentation on push and branch deletion ## 📝 Summary: The article shows how to delete a specific remote Git branch and simplifies the task with a convenient Git alias. The base command is: “git push origin --delete <branch-name>”. To streamline deleting the remote branch that matches your current local branch, it proposes a global alias: git config --global alias.drb '!git push origin --delete $(git rev-parse --abbrev-ref HEAD)'. After this, running “git drb” deletes the corresponding branch on the default remote (origin). An example demonstrates deleting chore/fix-typo by either the raw command or the alias. Key quotes: - “Typically when I want to delete a remote branch, I want to delete the branch on the remote named origin with the same name as the local branch I’m currently on.” - “You can add this alias by running... git config --global alias.drb '!git push origin --delete $(git rev-parse --abbrev-ref HEAD)'” - “In this situation, running git drb will behave the same as running git push origin --delete chore/fix-typo” ## 📖 Main Content: The piece focuses on repeatable Git hygiene tasks for developers working with remotes. It begins with the common scenario: once a feature branch is merged, you want to remove its remote counterpart on origin. While you can always type the full command with the exact branch name, it’s error-prone and repetitive. The author wraps the action in a Git alias that dynamically resolves the current branch name using git rev-parse --abbrev-ref HEAD, then passes that to git push origin --delete. This reduces cognitive load, prevents typos, and encourages regular cleanup of stale remote branches. The example illustrates parity between the explicit and aliased commands, reinforcing trust in the alias. Personal reflection: This micro-automation exemplifies the “sharpen the saw” mindset in developer workflows. It’s small but frequently used, hence high ROI. Extending the idea, one might create complementary aliases for safety, such as a dry-run check, or variants that prompt for confirmation in protected branches. ### 🗒️ Notes - Problem addressed - Frequent need to delete a remote branch on origin after merging - Manual typing is repetitive and prone to mistakes - Base command - git push origin --delete <branch-name> - Works for any named branch - Alias approach - Global alias: git config --global alias.drb '!git push origin --delete $(git rev-parse --abbrev-ref HEAD)' - Behavior: resolves current local branch and deletes matching remote branch on origin - Benefits: speed, consistency, reduced typos - Example - On chore/fix-typo: - Raw: git push origin --delete chore/fix-typo - Alias: git drb - How it works - git rev-parse --abbrev-ref HEAD outputs current branch name - The alias injects it into git push origin --delete - Practical considerations - Assumes default remote is origin - Requires permission to delete remote branches - Consider safeguards on main/default branches - Confirm branch merged before deletion to avoid losing collaboration context - Possible extensions - Add alias for listing merged branches - Add confirmation prompt for protected branches - Create variant alias for non-origin remotes ## 📖 References: - Git reference on deleting remote branches: git push <remote> --delete <branch> - Git plumbing command: git rev-parse --abbrev-ref HEAD - Sal Ferrarello’s article: https://salferrarello.com/git-delete-remote-branch/ ## 🗣️ Paraphrase: 1) Original idea: “Typically when I want to delete a remote branch, I want to delete the branch on the remote named origin with the same name as the local branch I’m currently on.” Paraphrase: In most cases, when I remove a branch from the remote, it’s the counterpart on origin that matches my current local branch. 2) Original command snippet explanation: “You can add this alias by running... After running the above command git drb will work for you...” Paraphrase: Set up the alias by running the provided git config command. Once that’s done, “git drb” will delete the remote branch corresponding to whatever branch you’re currently on. ## 📰 Newsletter: Learning web development is a lot smoother when your tools get out of the way. This week’s pro-tip: streamline your Git cleanup. If you’ve already merged a feature branch, skip the long command and use a handy alias to delete the remote branch on origin that matches your current local branch: git config --global alias.drb '!git push origin --delete $(git rev-parse --abbrev-ref HEAD)' Now, “git drb” does the heavy lifting—less typing, fewer typos, cleaner repos. Recent updates: WordPress 6.x performance wins continue to shine, and the block editor ecosystem keeps expanding with smarter design tools. Community highlights include new contributor mentorship cohorts and sustainability conversations around funding open-source maintenance. New plugins worth a look: performance profiling tools, image optimization helpers, and CI-friendly deployment utilities. If you’re mentoring new contributors or running team workshops, this tiny alias is a great on-ramp to customizing Git workflows. Pair it with branch protection and PR templates for a slicker developer experience. For deeper Git tips, check out Git’s docs on [branch deletion syntax](https://git-scm.com/docs/git-push#Documentation/git-push.txt---delete) and resolving the [current branch name](https://git-scm.com/docs/git-rev-parse). ## ✅ Action Items: Prompt for aligning articles with your advocacy and OSPO goals: “Analyze how this article supports open-source advocacy, contributor onboarding, and sustainable community practices within the WordPress ecosystem. Specifically: - Contributor Experience: Explain how this Git technique reduces friction for new and existing contributors, promotes repository hygiene, and aligns with transparent branch lifecycle policies. - Education: Outline how to teach this concept in workshops (beginner to advanced), including risks (e.g., deleting unmerged branches), safeguards (branch protection, confirmations), and hands-on labs. - Governance/OSPO: Describe how standardized Git aliases and conventions can be documented in an engineering handbook, integrated into contributor guides, and enforced via automation; discuss impacts on compliance, auditability, and inclusive practices. - Sustainability & Inclusivity: Show how small workflow improvements scale across teams, reduce cognitive load, and make contributing more accessible to diverse skill levels; propose metrics to measure adoption and impact. - Advocacy & Communication: Provide messaging for talks, blog - Summary: To delete a remote branch named chore/fix-typo from the default remote named origin in Git, use the command "git push origin --delete chore/fix-typo." To simplify this process, users can create a Git alias by running the command "git config --global alias.drb '!git push origin --delete $(git rev-parse --abbrev-ref HEAD).'" This alias will delete the remote branch with the same name as the current local branch when the user types "git drb." The alias runs the same command as the original, but includes the current branch name. - URL: https://salferrarello.com/git-delete-remote-branch/ This is the command I run when I want to delete a branch named `chore/fix-typo` from the default remote (which is named `origin`): `git push origin --delete chore/fix-typo` #### Making My Life Easier Typically when I want to delete a remote branch, I want to delete the branch on the remote named `origin` with the same name as the local branch I’m currently on. To make my life easier I’ve setup a Git alias to do this when I type `git drb`, for “d(elete) r(emote) b(ranch)”. You can add this alias by running the following from the command line: ``` git config --global alias.drb '!git push origin --delete $(git rev-parse --abbrev-ref HEAD)' ``` After running the above command `git drb` will work for you and if you look in your Git config (`~/.gitconfig`), you’ll see a section that looks like ``` [alias] drb = !git push origin --delete $(git rev-parse --abbrev-ref HEAD) ``` ##### An Example For example, if I’m on the branch `chore/fix-typo`, I want to delete the branch on the remote `origin` named `chore/fix-typo`. In this situation, running `git drb` will behave the same as running `git push origin --delete chore/fix-typo` ##### How this Alias Works The alias runs `git push origin --delete` followed by the current branch name (see [Git Get Current Branch Name](https://salferrarello.com/git-get-current-branch-name/) for more information on how this works). ![Sal Ferrarello](https://secure.gravatar.com/avatar/f7bea39ff77df472cc4e3c29e40d3e46?s=256&d=mm&r=g) Sal is a PHP developer with a focus on the WordPress platform. He is a [conference speaker](https://salferrarello.com/speaking) with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at [WebDevStudios](https://webdevstudios.com), where he works as a senior backend engineer., Git Delete Remote Branch, Sal Ferrarello, 01gyw7q71rynccs017qvnqc5y7.