How to clear the list of branches?

After cloning the repo from the remote, I am in a branch master. When you enter git branchto view the list of branches in the list will be only master.

Over time, we check existing branches, and also create new branches, connecting a new work with masterand clicking on origin. Now, having typed git branch, you will see a long list with dozens of branches.

How can I reduce the list by deleting certain branches from the list, keeping others in the list?

Update 1 . To clarify, I'm not interested in deleting any branch from the repo (and, definitely, not from the remote repo). Just simplifying navigation between the subset of branches that I regularly use at a given time.

Update 2 : Consider -

$ git clone myrepo
$ git branch
        * master
$ git checkout mybranch
$ git branch
          master
        * mybranch
$ git checkout master
$ git branch
        * master
          mybranch
$ git "I'll not be dealing with mybranch for 91 days, do something to clean the list"
$ git branch
        * master

(playing DOOM for 91 days)

$ git checkout mybranch
$ git branch
          master
        * mybranch
+4
3

git branch .git/refs/heads, . , , git branch.

$ git branch
* branch-1
  master
  trunk
$ ls .git/refs/heads/
branch-1  master  trunk
$ rm .git/refs/heads/master
$ git branch
* branch-1
  trunk
$
+1

. , .

. .

- , master.

git branch -d $(git branch --merged | grep -vw $(git rev-parse --abbrev-ref HEAD))

, ( 90 ) git reflog.

+3

First list all the local branches:

$ git branch

We need to know which branches are already merged into "master" and can be easily removed:

$ git checkout master
$ git branch --merged

Now delete all obsolete branches with:

$ git branch -d old-merged-feature

Next, decide what to do with unjoined branches:

$ git branch --no-merged

If some of them are simply abandoned, which you no longer need, delete it using the “-D” option:

$ git branch -D old-abandoned-feature
0
source

Source: https://habr.com/ru/post/1672014/


All Articles