How to Delete a Git Branch (Locally and Remotely)

Deleting a Git Branch Remotely

git push -d <remote_name> <branch_name>
  • remote_name: the name of the remote repository you're interacting with. If you don't remember changing this, it's most like just origin

  • branch_name: the name of the remote branch you'd like to delete

Common Errors

Branch Doesn't Exist on the Remote
error: unable to delete '<branch_name>': remote ref does not exist

Here are some troubleshooting steps you can try:

  • Make sure you're in the correct git directory on your machine

  • Make sure the branch you're trying to delete actually exists. Run git branch -r to list all of the remote git branches belonging to your repo.

  • Make sure the branch you're trying to delete exists in the remote repository you provided. Run git branch -r to get a list of all the remote repos and their branches.

Remote Repository Doesn't Exist
fatal: '<remote_name>' does not appear to be a git repository

Here are some troubleshooting steps you can try:

  • Make sure you're in the correct git directory on your machine

  • Make sure the remote repository you're providing actually exists. You can run git remote -v to list all of the remote remote repositories associated to your repo


Deleting a Git Branch Locally

git branch -d <branch_name
  • branch_name: the name of the local git branch you'd like to delete

Common Errors

Branch Not Found
error: branch '<branch_name>' not found

Here are some troublshooting steps you can try:

  • Make sure you;re in the correct git directory on your machine

  • Make sure the branch you're trying to delete actually exists. Run git branch to list all of the git branches you have stored locally

A single code search interface for all your repos

Search across all your repos (GitHub, GitLab, BitBucket, etc) using a single open-source, blazingly fast, and feature-rich interface.

A single code search interface for all your repos

Search across all your repos (GitHub, GitLab, BitBucket, etc) using a single open-source, blazingly fast, and feature-rich interface.