Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It is safe to delete a tagged but un-merged Git branch?

Tags:

git

I've seen other posts about how it is safe to delete a branch that has been merged, but is it also safe to tag a branch and then delete that branch?

I would like to branch off an old release, make a fix and then tag it without merging it back into master. I don't like to leave open branches, so I would prefer to delete it once it has been tagged.

I would still like to be able to click the tag in SourceTree and view the history as if it were still on a branch.

like image 597
row1 Avatar asked Dec 13 '25 21:12

row1


1 Answers

Yes, it is safe. Read there https://stackoverflow.com/a/2617160/2656799

In Git, branches are just pointers (references) to commits in a directed acyclic graph (DAG) of commits. This means that deleting a branch removes only references to commits, which might make some commits in the DAG unreachable, thus invisible. But all commits that were on a deleted branch would still be in the repository, at least until unreachable commits get pruned (e.g. using git gc).

If you tag the branch before deletion, all it's commits still reachable, and wouldn't be touched by gc.

like image 184
ephemerr Avatar answered Dec 15 '25 12:12

ephemerr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!