How to delete (multiple) branches from a Git repository?

Asked

Viewed 483 times

0

I want to create a repository Fork that has dozens of branches, but I will only use 2 branches.

I wanted to know A simple way to delete all branches that I won’t use because I’ve been trying to delete them but I couldn’t.

I know that commit history is important and that I could simply use an entire project Fork, but it turns out that there are actually many branches and most commits in the other branches have nothing to do with the ones I use, i.e., the commit history of these does not interest me and does not affect the branches I will work on in any way.

Also, this project doesn’t have a master branch for some reason, so commit histories are quite different in each branch.

1 answer

1

You can create a main branch (it was meant to be the Master, but that’s okay), and merge to specify conflicts.

git merge --no-ff nome-branch

And then you can do it here:

git branch -D 3.2 3.2.1 3.2.2

Basically, git branch will delete multiple branches for you with a single invocation. Unfortunately, it doesn’t complete the agency name. Although, in bash, you can do:

git branch -D `git branch | grep -E '^3\.2\..*'`
  • In the case of that 3.2 3.2.1 3.2.2, what this means exactly (so I can understand what is happening in this command)

  • In addition to that ( and to be more specific), I was thinking here a little while ago and ideally I would have a master branch (some changes will affect the whole project) and the 2 specific branches I will be working on. Each one has its particularities but there are several changes that will be common to Mboa, and using the current project structure I would have problems if I didn’t have a master branch.

  • I’m specifying the Branchs I want to delete, you have to give me the name of the branch you want to delete. In this command I am saying that I want to erase (local) the Branchs (3.2, 3.2.1, 32.2).

  • So I informed you that you should have a Main Branch(Master).

Browser other questions tagged

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