From charlesreid1

Start by cloning the repository.

We'll assume you've cloned the master branch, and the remote branch is still sitting in Github.

The procedure is as follows:

  • Fetch all remote branches
  • Check out the remote branch as a local branch
  • Check out the master branch
  • (NOTE: If you already have a local copy of the remote branch to delete, start with the step below.)
  • Delete the local branch
  • Push the (deleted) local branch to the remote

It sounds a bit confusing, so we'll walk through it step by step.

For example, suppose we're trying to delete the oxen-translation branch below:

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/oxen-translation

First, update the list of remote repositories with git fetch, just to make sure you're seeing all of the latest remote repositories:

$ git fetch --all

Next, check out the remote branch as a local branch (which will give us the ability to delete it):

$ git checkout -b oxen-translation remotes/origin/oxen-translation
Branch oxen-translation set up to track remote branch oxen-translation from origin.
Switched to a new branch 'oxen-translation'

Now we have a local copy of the branch that is linked to the remote branch. Now we need to delete the branch. We can't have the branch we want to delete checked out when we delete it, so switch back to the master branch:

$ git checkout master

NOTE: If you already had a local copy of the remote branch to delete, start here.

Now delete the local version of the remote branch:

$ git branch -d oxen-translation
warning: deleting branch 'oxen-translation' that has been merged to
         'refs/remotes/origin/oxen-translation', but not yet merged to HEAD.
Deleted branch oxen-translation (was daa010c).

Now, we push the (deleted) branch to the remote, which will delete the branch remotely:

$ git push origin :oxen-translation

Alternatively,

$ git push origin --delete oxen-translation