2

I have created a branch where I was trying an approach to a problem which didn't work out, so I want to delete the branch, including all commits I made on it. For the sake of the argument, my branches look like this (when viewed with Gitk):

A--B--C--D Master
    \
     \-E-F Unwanted

I want it to look like this:

A--B--C--D Master

If I delete the Unwanted branch I end up with this instead:

A--B--C--D Master
    \
     \-E-F

I have no use for commits E and F, and don't want them cluttering my Git history.

Apologies for what may seem to be a very simple (and possibly stupid) question, but I've been unable to find a suitable answer elsewhere.

1

2 Answers 2

5

No, that's all you do. As long as E and F aren't referenced in any branch or tag, they'll eventually be garbage collected. I assume you're looking at it in gitk and still see the commits hanging out. If you restart gitk or do a forced reload with Ctrl+F5, they'll disappear. They're still there, but git will take care of them eventually. While you can force them to be cleaned up immediately, that's not a good habit to get into. The default time-to-live of 2 weeks for orphaned commits is there because just sometimes you really did want those commits, and you just didn't know it yet, so leave them orphaned and move on.

3

If you run git gc it will remove unreferenced branches (which F is, assuming you didn't tag it or derive other branches from it) when they are older than a certain threshold (2 weeks default, and you can adjust it with --prune=<date>).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.