3

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.

row1
  • 5,568
  • 3
  • 46
  • 72
  • Deleting a branch doesn't delete commits http://stackoverflow.com/a/2613954/1351828 – Adrian Krupa Nov 30 '15 at 02:19
  • @AdrianKrupa I had seen that answer before posting, but my understanding of it is that if you delete without merging, then the commits on the deleted branch will eventually be cleaned up when garbage collecting. – row1 Nov 30 '15 at 04:35

2 Answers2

1

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.

ephemerr
  • 1,833
  • 19
  • 22
-1

There's nothing stopping you from keeping a tag that's not in a branch.

Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
  • So if I were to view the history for the tag I would still see all of the commits as if the branch was still there? – row1 Nov 30 '15 at 02:10
  • "as if the branch was still there". I'm not sure what you're asking, but I guess the answer is yes. A branch and a tag are exactly the same thing: they are a pointer to a specific commit. The only difference is that when you checkout a branch and make a new commit, the pointer moves to the new commit, whereas a tag always stays put. – Joseph Silber Nov 30 '15 at 02:36
  • I mean visually appearing as a branch in a tool like SourceTree. You will see all of the commits for the tag coming off master. – row1 Nov 30 '15 at 04:31