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?
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.
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).
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.
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.
Local Branch
git branch -D local_branch
Remote Branch
git push origin --delete remote_branch
As with every git
server:
$ git push github :<BRANCH_NAME>
or:
$ git push github --delete <BRANCH_NAME>
Example:
$ git push github --delete test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With