After cloning a repo from the remote, I am on the master
branch. When typing git branch
to view the branch list, there's only master
in the list.
Over time, checking out existing branches as well as creating new branches, eventually merging new work into master
and pushing to origin
. Now, typing git branch
shows a long list with dozens of branches.
How can I reduce the list, removing specific branches from the list while retaining others on the list?
Update 1: To clarify, I am not interested in deleting any branch from the repo (and definitely not from the remote repo). Just making it easier to navigate between the subset of branches 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
I don't want to delete the branches. I want them to still exist in the repo. I just want to clean the list
You would still need to delete those local branches. That won't delete them on the remote repo.
One good policy is to delete any branch merged to master
.
git branch -d $(git branch --merged | grep -vw $(git rev-parse --abbrev-ref HEAD))
Don't forget you can restore any deleted branch (if done within the past 90 days) through git reflog
.
git branch
command lists branches using files from the location .git/refs/heads
, here you can find files with branch names. Each file in this location corresponds to a branch, remove the files for which you don't want to see the branch in git branch
command's output.
$ git branch
* branch-1
master
trunk
$ ls .git/refs/heads/
branch-1 master trunk
$ rm .git/refs/heads/master
$ git branch
* branch-1
trunk
$
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