49

I have a git repository in my local machine:
I add a new branch called test and add a few commits
Then I checkout to master branch and add commits to it.
So I use git push --all github and continue working on master. After some time I decide to completely remove the test branch and use: git branch -d test and git branch -r -d github/test, but it only deletes the local branch used for tracking the actual test branch as git says:

Deleted remote-tracking branch github/buggy (was acc5a58).

I'm asking if there's a way to actually remove the test branch from github servers from command-line?

2

3 Answers 3

72

Local Branch

git branch -D local_branch

Remote Branch

git push origin --delete remote_branch
4
  • 2
    git push origin :remote_branch
    – ut9081
    Aug 5, 2020 at 14:18
  • 1
    For the deleting local branch, the delete flag should be uppercase. Like this git branch -D local_branch
    – Edgar256
    Jul 29, 2021 at 2:39
  • Thanks for pointing it out. Updated! Jul 30, 2021 at 18:44
  • git push origin :remote_branch only works if you've deleted the local branch. The answer as posted is better, since it treats the two cases independently. Feb 23 at 19:25
39

As with every git server:

$ git push github :<BRANCH_NAME>

or:

$ git push github --delete <BRANCH_NAME>

Example:

$ git push github --delete test
2
  • 1
    For future readers - if you want to list all the remote branches (in Github) try: git branch -r
    – BenKoshy
    Mar 20, 2019 at 9:20
  • Not only in Github, it's git feature. And each basic git tutorial describes it. Mar 20, 2019 at 11:11
2

Use this command:

git push github :test

Read "push nothing as refname test on github remote"

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.