In Git, branches are just pointers (references) to commits in a directed acyclic graph (DAG) of commits. This means deleting a branch only removes commit references, which can make some commits in DAG unreachable, therefore invisible. But all commits that were in a deleted branch will still be in the repository, at least until the unreachable commits are pruned ("pruned", for example using git gc).
Notice that git branch -d
will refuse to delete a branch if you cannot guarantee that removing it will not make commits unreachable. If you really want to remove it, you need to use git branch -D
to force the deletion of a branch that can make commits unreachable.
Also note that unreachable commits, if any, are only those between the last tip of a deleted branch and a commit that has been merged into another existing branch, or the point where the branch has emerged; whichever is last. For example in this situation:
----O----*----*----/M----* <-- master <-- HEAD
\ /
\--.----.--/--x---y <-- branch deletado
Only x and y commits will be unavailable after deleting the branch.
This text was extracted and translated from the Jakub Narębski in another question, where you can read more about it in English.
Related: When branches are useful in Git?
– Caffé