What's the difference between 'closing' and 'deleting' a branch?
I see these two terms bandied about but I'm not sure what they mean precisely in the context of Git. Are they both effectively referring to the same thing (git branch -d
) or is there some subtle difference of which I should be aware?
I may be wrong but so far my understanding is that, unless I tag the branch prior to deletion, once the branch is deleted there's no evidence left behind that it ever existed. Correct?
There is no explicit command in git that is referred to as a close
it is possible that by convention, some programmers refer to a branch as "closed" when it is merged back into the project and is no longer being maintained. Sometimes the branch is kept around, other times it is deleted, but the idea is that it is not being used anymore.
To answer your second question, there are a few ways you can keep track of a branch after you delete it. The most common way is via a remote host. Running git -d branch_name
will only destroy your local copy. The remote host will still have its version in case you need it later. You can also stash the branch you are about to delete and come back to it later. This is how you stash
git stash save "I'm saving this branch before I delete it because yolo"
Here is a link on how to use stash to achieve your end, but your end it an unusual use case: https://www.kernel.org/pub/software/scm/git/docs/git-stash.html
Basically, if you stash your branch then you would have a record of its existence after deleting it. Additionally, if you merged that branch into other branches then those branches still know something about the existence of the deleted branch (mostly just that it existed). Again you can see what a given branch knows about its own merge history with git log --graph
There may be other ways that a branch can be seen in some fashion after deletion, but this should not be an issue for most workflows.
I've since come to appreciate that to "close a branch" roughly equates to to "delete all local and remote copies of the branch".
The difference is that Deleting the branch is just one technical sub-step of conceptually Closing the branch.
Closing is a broad reference to permanently removing a branch from the team's mindset which glosses over the messy details of merging, or abandoning, or whatever is necessary to make it a thing of the past.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With