Ravazz
Ravazz

Reputation: 125

Remove completely a local branch

I have a repo in a very small environment with a short amount of memory, so every byte counts. I just finished developing, so I want to remove the dev branch. Now, my repo is structured like this:

(master) A---------E
(dev)     \-B-C-D-/

I've already tried git branch -d dev, but it ends up deleting dev keeping all the commits, like this:

(master) A---------E
          \-B-C-D-/

Is there a way to keep only the master branch? Like

(master) A---------E

Thanks.

Upvotes: 0

Views: 98

Answers (1)

SebDieBln
SebDieBln

Reputation: 3469

A "branch" is merely a label for a commit. So deleting a branch just frees up some bytes. The commit E still points to D so this commit will not be deleted by the git garbage collection. Same for C because it is pointed to by D and so on.

The suggested method of rebasing/squash merging will get rid of these commits. So you will loose B-C-D and E and they will all be replaced with a new commit F.

If you are really short on disk space and don't care about the history (maybe because you have a clone somewhere else), you could make your repo shallow This will get rid of all the commits except E. There a quite a few ways to achieve this, covered in this question: Converting git repository to shallow?

Upvotes: 1

Related Questions