How do I delete a local and remote Git branch(branch)?

Asked

Viewed 97,159 times

31

I want to delete a local branch and in my remote project on Github.

3 answers

64


To delete the branch locally:

git branch -D <nome do branch>

To delete the branch remotely:

git push <nome do origin> <nome do branch> --delete
  • 1

    I used the command to delete the remote repository and gave error saying that there is no branch. I only created the repository, but this is Windows. git push <origin name> <branch name> -delete The origin name is what? In my case, I named the repository Test. And the branch?

14

You can use the following command:

git push origin :nome_do_branch

Paying attention to the : in front of the branch name, as it is the one who will cause the branch to be deleted, otherwise you would be updating the remote branch.

  • 1

    He wants to delete branch, not upload his commits!

  • 10

    Juarez Lustosa’s response for some reason has been negative and still has a comment saying that "he wants to delete branch, not upload his commits". But it is a valid answer, used to exclude remote branchs, and simpler than the others cited. before nome_do_branch has two points (:) and that’s what makes deleting the branch and not pushing.

  • Thanks Rafael Macedo!!! That’s exactly it!.

6

To remove local branch:

 git branch -d nome-do-branch

And to remove remote branch add the "-r flag":

 git branch -dr origin/nome-do-branch
  • git branch -dr origin/branch name About this command, where do I put the name of my repository I called Test? I created a repository, but I didn’t create a branch, I didn’t commit, I didn’t do anything. I can’t delete the Test Protocol. Note, I only have a remote, I didn’t clone it. I just want to learn how to delete this project.

  • I don’t know, André. This command there is only to remove branches even, not repositories.

  • @You can access this tutorial to learn how to delete a repository from Github https://help.github.com/articles/deleting-a-repository/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.