Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete remote branch (e.g. Github) from command line? [duplicate]

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?

like image 499
Masked Man Avatar asked Oct 04 '16 13:10

Masked Man


People also ask

How do I remove a remote git branch from terminal?

Instead of using the git branch command that you use for local branches, you can delete a remote branche with the git push command. Then you specify the name of the remote, which in most cases is origin . -d is the flag for deleting, an alias for --delete . remote_branch_name is the remote branch you want to delete.

How do I delete a GitHub repository branch?

On GitHub.com, navigate to the main page of the repository. Above the list of files, click Branches. Scroll to the branch that you want to delete, then click . If you try to delete a branch that is associated with at least one open pull request, you must confirm that you intend to close the pull request(s).

How do I remove a remote from GitHub?

The git remote remove command removes a remote from a local repository. You can use the shorter git remote rm command too. The syntax for this command is: git remote rm <remote-url>. If you remove a remote accidentally, you will need to add it back manually using the git remote add command.

How do I delete a local and remote branch?

So, to delete the remote branch AND locally-stored remote-tracking branch in one command, just use git push origin --delete <branch> . Then, you just need to delete the local branch with git branch -D branch . That covers the deletion of all 3 branches with only 2 commands.


2 Answers

Local Branch

git branch -D local_branch 

Remote Branch

git push origin --delete remote_branch 
like image 125
Mihir Patel Avatar answered Oct 11 '22 10:10

Mihir Patel


As with every git server:

$ git push github :<BRANCH_NAME> 

or:

$ git push github --delete <BRANCH_NAME> 

Example:

$ git push github --delete test 
like image 41
Arkadiusz Drabczyk Avatar answered Oct 11 '22 09:10

Arkadiusz Drabczyk