Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between 'closing' and 'deleting' a branch?

Tags:

git

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?

like image 937
John Mee Avatar asked Jul 10 '13 23:07

John Mee


2 Answers

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.

like image 100
usumoio Avatar answered Sep 24 '22 21:09

usumoio


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.

like image 44
John Mee Avatar answered Sep 25 '22 21:09

John Mee